标签:
1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 using namespace std; 5 6 int main() 7 { 8 int c[1005]; 9 int w[1005]; 10 int dp[1005]; 11 int t,V,v,i,n; 12 scanf("%d",&t); 13 while(t--) 14 { 15 memset(dp,0,sizeof(dp)); 16 scanf("%d%d",&n,&V); 17 for(i=1;i<=n;i++) 18 scanf("%d",&w[i]); 19 for(i=1;i<=n;i++) 20 scanf("%d",&c[i]); 21 for(i=1;i<=n;i++) 22 for(v=V;v>=0;v--) 23 { 24 if(v-c[i]>=0) 25 dp[v]=max(dp[v],dp[v-c[i]]+w[i]); 26 } 27 printf("%d\n",dp[V]); 28 } 29 return 0; 30 }
标签:
原文地址:http://www.cnblogs.com/homura/p/4763867.html