Ultraviolet A 12563 Jin Ge Jin Qu hao (DP)
Train of Thought: DP, with the idea of 01 backpack, each record the maximum number of songs at each time, and finally find the answer to satisfy the maximum number of songs, the maximum number of times
# Include
# Include
# Include using namespace std; const int N = 55; int T, n, t, sing [N], dp [11005]; int main () {int cas = 0; scanf (% d, & T); while (T --) {scanf (% d, & n, & t); for (int I = 0; I <n; I ++) scanf (% d, & sing [I]); sing [n ++] = 678; memset (dp,-1, sizeof (dp )); dp [0] = 0; for (int I = 0; I <n; I ++) {for (int j = min (t-1, 10000 ); j> = 0; j --) {if (dp [j]! =-1) dp [j + sing [I] = max (dp [j + sing [I], dp [j] + 1 );}} int ans1 = 0, ans2; for (int I = 11000; I> = 0; I --) {if (ans1 <dp [I]) {ans1 = dp [I]; ans2 = I ;}} printf (Case % d: % d, ++ cas, ans1, ans2) ;}return 0 ;}