标签:dp
#include<iostream> #include<memory.h> using namespace std; int dp[10010]; int max(int a,int b) { return a>b?a:b; } int main() { int n,v,vi[10100],wi[10100],i,j; while(cin>>n>>v) { memset(vi,0,sizeof(vi)); memset(wi,0,sizeof(wi)); for(i=0;i<n;i++) cin>>wi[i]; for(i=0;i<n;i++) cin>>vi[i]; memset(dp,0,sizeof(dp)); for(i=0;i<n;i++) for(j=vi[i];j<=v;j++) dp[j]=max(dp[j],dp[j-vi[i]]+wi[i]); cout<<dp[v]<<endl; } return 0; }
标签:dp
原文地址:http://blog.csdn.net/r_misaya/article/details/40514199