USACO 3.4 Raucous Rockers(DP)
凭着感觉写的,维数有点多,脑子就有点乱。。状态转移,还是挺好想的,开个标记数组记录j-1的最大唱片数。
1 /* 2 ID: cuizhe 3 LANG: C++ 4 TASK: rockers 5 */ 6 #include <cstdio> 7 #include <cstring> 8 #include <iostream> 9 #include <cmath> 10 using namespace std; 11 int dp[21][21],o[21]; 12 int p[21]; 13 int main() 14 { 15 int i,j,k,n,t,m,maxz; 16 freopen("rockers.in","r",stdin); 17 freopen("rockers.out","w",stdout); 18 scanf("%d%d%d",&n,&t,&m); 19 for(i = 1; i <= n; i ++) 20 scanf("%d",&p[i]); 21 maxz = 0; 22 for(i = 1; i <= n; i ++) 23 { 24 for(j = 1; j <= m; j ++) 25 { 26 for(k = t; k >= p[i]; k --) 27 { 28 dp[j][k] = max(o[j-1]+1,dp[j][k]); 29 dp[j][k] = max(dp[j][k],dp[j][k-p[i]]+1); 30 } 31 } 32 for(j = 1; j <= m; j ++) 33 { 34 for(k = 1; k <= t; k ++) 35 o[j] = max(o[j],dp[j][k]); 36 } 37 } 38 for(j = 1; j <= m; j ++) 39 { 40 for(k = 1; k <= t; k ++) 41 { 42 maxz = max(maxz,dp[j][k]); 43 } 44 } 45 printf("%d\n",maxz); 46 return 0; 47 }