01-bag
#include#include #include int main(){ int t; int n,v; int c[1100],w[1100]; int dp[1100]; int i,j; scanf("%d",&t); while(t--){ scanf("%d%d",&n,&v); for(i=1;i<=n;++i){ scanf("%d",&w[i]); } for(i=1;i<=n;++i){ scanf("%d",&c[i]); } memset(dp,0,sizeof(dp)); for(i=1;i<=n;++i){ for(j=v;j>=c[i];--j){ dp[j]=fmax( dp[j] , dp[j-c[i]]+w[i]); } } printf("%d\n",dp[v]); } return 0;}
posted on 2013-11-17 15:10 阅读( ...) 评论( ...)