HDU 2191 Cherish now, Thanksgiving life DP

Source: Internet
Author: User

Mourning for 512 Wenchuan earthquake--cherish now, Thanksgiving lifeTime limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 16047 Accepted Submission (s): 6790


Problem description Urgent! The food in the disaster area is still short!
In order to save the lives of compatriots in the disaster area, you are prepared to purchase some food support disaster areas, now suppose you have a total of funds N, and the market has m rice, each rice is bagged products, its price range, and can only buy the whole bag.
Excuse me: How many kilograms of grain can you purchase with limited funds?

Postscript:
Life is a life process full of variables, natural disasters, man-made disasters, sickness is the unpredictable threat of our life.
The moon has a cloudy and clear circle, people have unforeseen, the future for us is an unknown. So, what we should do is to cherish the present, Thanksgiving life-
Thank the parents, they give us life, raise our adult;
Thank teachers, they give us knowledge, teach us to be a man
Thank the friends, they let us feel the warmth of the world;
Thanks to the opponents, they make us keep making progress and efforts.
Likewise, we would like to thank the pain and hardship brought to our wealth ~



Input data first contains a positive integer c, which indicates that there is a C set of test cases, the first line of each set of test cases is two integers n and m (1<=n<=100, 1<=m<=100), respectively, the amount of money and the type of rice, then the M row of data, Each line contains 3 numbers of P,h and C (1<=p<=20,1<=h<=200,1<=c<=20), each of which represents the price per bag, the weight of each bag, and the number of bags for the corresponding type of rice.
Output for each set of test data, export the maximum weight that can be purchased for rice, and you can assume that you are spending more than all of the rice, and you can afford to spend it. The output for each instance takes up one row.
Sample Input
18 22 100 44 100 2

Sample Output
400



</pre><pre name= "code" class= "CPP" > #include <iostream> #include <cstring>using namespace std; #define M 105int D[m];int Main () {    int t;    cin>>t;    while (t--) {        int n,m;        cin>>m>>n;        int i,j;        int a[m],b[m],c[m];        for (i=1;i<=n;i++)            cin>>a[i]>>b[i]>>c[i];        memset (d,0,sizeof D);        for (i=1;i<=n;i++) for (            int. k=1;k<=c[i];k++) for                (j=m;j>=a[i];j--)                    D[j]=max (D[j],d[j-a[i]] +b[i]);        cout<<d[m]<<endl;    }    return 0;}


HDU 2191 Cherish now, Thanksgiving life DP

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.