Title Link: http://uva.onlinejudge.org/external/125/12563.pdf
Idea: DP, with 01 backpack ideas, each time the maximum number of songs, the last to find answers first to meet the maximum number of songs, in the time to meet the largest
#include <cstdio> #include <cstring> #include <algorithm>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%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 (in T 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%d\n", ++cas, Ans1, ANS2); }return 0;}
UVA 12563 Jin Ge jin Qu hao (DP)