Original title Link http://acm.hdu.edu.cn/showproblem.php?pid=5410
Because he gets an AI candy for every item he buys, he gets bi sugar for every item he buys. There are two values: So we should first use a 01 backpack to unify the two values ... Because each item in the 01 backpack can only be taken once .... Then we use multiple backpacks to decide which items we should buy more of the most candy .... ==
#include <stdio.h>#include<string.h>#include<iostream>#include<algorithm>using namespacestd;Const intmaxn=1010; __int64 dp[ .];intW[MAXN],A[MAXN],B[MAXN];intMain () {intt,n,w; scanf ("%d",&t); while(t--) {memset (DP,0,sizeof(DP)); inti,j; scanf ("%d%d",&w,&N); for(i=1; i<=n;i++) scanf (" %d%d%d",&w[i],&a[i],&B[i]); for(i=1; i<=n;i++) { for(j=w;j>=w[i];j--) {Dp[j]=max (dp[j],dp[j-w[i]]+a[i]+B[i]); } } for(i=1; i<=n;i++) { for(j=0; j<=w;j++) { if(j>=W[i]) dp[j]=max (dp[j],dp[j-w[i]]+A[i]); }} printf ("%i64d\n", Dp[w]); } return 0;}
CRB and his Birthday (more than 2015 schools)