題意:赤裸裸的01背包
#include#include #include #include using namespace std; const int MAXN = 1010; int v[MAXN],w[MAXN],f[MAXN]; int N,V; int main(){ int t; scanf("%d",&t); while (t--){ scanf("%d%d",&N,&V); memset(v,0,sizeof(v)); memset(w,0,sizeof(w)); memset(f,0,sizeof(f)); for (int i = 1; i <= N; i++) scanf("%d",&w[i]); for (int i = 1; i <= N; i++) scanf("%d",&v[i]); for (int i = 1; i <= N; i++) for (int j = V; j >= v[i]; j--) f[j] = max(f[j],f[j-v[i]]+w[i]); printf("%d\n",f[V]); } return 0; }