Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4508
Question:
Given some data.
Each group of data starts with an integer N, indicating that there are n kinds of foods in the daily food list.
In the next n rows, there are two integers A and B in each row. A indicates that this food can bring the greater the value, the happier the value ), B indicates the amount of calories consumed by zookeeper.
The final value is an integer m, which indicates that the number of calories absorbed in a day cannot exceed M.
Ideas:
Full backpack.
Initially thought it was a 01 backpack.
If you have knocked 01, Example 2 is incorrect !!!
And then it's done .. Just change the loop body ..
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int MAXN=100000+10;int w[MAXN],v[MAXN];int dp[MAXN];int main(){int n,m;while(~scanf("%d",&n)){for(int i=1;i<=n;i++)scanf("%d%d",&v[i],&w[i]);scanf("%d",&m);memset(dp,0,sizeof(dp));for(int i=1;i<=n;i++){for(int j=w[i];j<=m;j++){dp[j]=max(dp[j],dp[j- w[i]] + v[i]);}}printf("%d\n",dp[m]);}return 0;}