Multiple identical backpacks for maximum value
F[I][K][J] previous I song with K-CD, K-CD's capacity for Max number of J
For the first song, you can put it on the previous CD or open a new CD.
In a normal backpack, f[j] represents the maximum value, so you can use F[k][j] to represent the maximum number of top K CDs
F[K][J] = max (f[k][j],f[k-1][t]+1); Open a new CD
F[K][J] = max (f[k][j],f[k][j-w[i]]+1); Put it on the original CD, Why do I not know
#include <iostream>#include<cstdio>using namespacestd;intf[ A][ A];//F[k][j] K-CD, the maximum number of K CD's capacity is Jintw[ A];intn,m,t;intMain () {scanf ("%d%d%d",&n,&t,&m); for(intI=1; i<=n;i++) scanf ("%d",&W[i]); for(intI=1; i<=n;i++) for(intk=m;k>=1; k--) for(intj=t;j>=w[i];j--) F[k][j]= Max (F[k][j],max (f[k-1][t],f[k][j-w[i]]) +1); printf ("%d", f[m][t]); }
View Code
Codevs 1444 "Broken Gong Rock" band