Story of the HDU 4508 cutting-edge series-I (First session of the 2013 Tencent programming marathon preliminary competition)

Source: Internet
Author: User

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;}





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.