标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 51417 Accepted Submission(s): 21634
#include<iostream> using namespace std; int main() { int t; int w[1050]; int v[1050]; int d[1050][1050]; while(cin>>t) { while(t--) { int n,c; cin>>n>>c; for(int i=1;i<=n;i++) cin>>w[i]; for(int i=1;i<=n;i++) cin>>v[i]; for(int i=1;i<=n;i++) for(int j=0;j<=c;j++) { d[i][j]=(i==1?0:d[i-1][j]); if(j>=v[i]) d[i][j]=max(d[i][j],d[i-1][j-v[i]]+w[i]); } cout<<d[n][c]<<endl; } } return 0; }
标签:
原文地址:http://www.cnblogs.com/hellohacker/p/5744928.html