题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602
#include <iostream> #include <string.h> using namespace std; /**************************************************************************************************************** 题意:狗吃骨头的 0/1 背包问题 思路: 1,狗吃骨头猫抓老鼠~~~ 2,其实是 0/1 背包,水水的~ 3,今天把 w和v 搞反了,恰好给的样例还特殊,wa了好几次,心累!!!要好好读题!好好学英语! ****************************************************************************************************************/ int w[1050],v[1050]; int dp[1050]; int main() { int T,n,V; cin>>T; while(T--) { memset(dp,0,sizeof(dp)); cin>>n>>V; for(int i = 1;i <= n;i ++) cin>>v[i]; for(int i = 1;i <= n;i ++) cin>>w[i]; for(int i = 1;i <= n;i ++){ for(int j = V;j >= w[i];j --) dp[j]=max(dp[j],dp[j-w[i]]+v[i]); } cout<<dp[V]<<endl; } return 0; }