标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 50442 Accepted Submission(s): 21153
#include<iostream> #include<stdio.h> using namespace std; const int maxx = 1005; int main(){ int t; scanf("%d",&t); while(t--){ int n,v; scanf("%d%d",&n,&v); int val[maxx]; int wei[maxx]; for(int i=1;i<=n;i++){ scanf("%d",&val[i]); } for(int i=1;i<=n;i++){ scanf("%d",&wei[i]); } int dp[maxx][maxx]; for(int i=0;i<=v;i++) dp[0][i]=0; for(int i=1;i<=n;i++){ for(int j=0;j<=v;j++){ if(j<wei[i]){ dp[i][j]=dp[i-1][j]; }else{ dp[i][j]=max(dp[i-1][j],dp[i-1][j-wei[i]]+val[i]); } } } printf("%d\n",dp[n][v]); } }
标签:
原文地址:http://www.cnblogs.com/superxuezhazha/p/5704210.html