HPU 2191 Mourning 512 Wenchuan earthquake--cherish now, Thanksgiving life "multiple backpack template"

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): 19561 Accepted Submission (s): 8280


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

Authorlcy
SOURCE2008-06-18 "ACM Program Design" Final Exam--Sichuan refueling!  China Refueling! Idea: To turn multiple backpacks into 01 backpacks, that is, there will be multiple of each backpack, you can convert it into a number of the same backpack, and then use 01 backpack to do OK! Code:
HDU 2191 Mourning 512 Wenchuan earthquake--cherish now, Thanksgiving life # include <stdio.h> #include <string.h> #include <algorithm> Using namespace Std;struct inin{int p,h;} A[105];int Bag[2005];int Main () {int t;int n,m;scanf ("%d", &t), while (t--) {memset (a,0,sizeof (a)); Memset (bag,0, sizeof (bag)), scanf ("%d%d", &n,&m), int u,v,w,t=0;for (int i=1;i<=m;i++) {scanf ("%d%d%d", &u,&v, &W); for (int j=1;j<=w;j++) {t++;a[t].p=u;a[t].h=v;}} for (int i=1;i<=t;i++) {for (int j=n;j>=a[i].p;j--) {Bag[j]=max (bag[j],bag[j-a[i].p]+a[i].h);}} printf ("%d\n", Bag[n]);} return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HPU 2191 Mourning 512 Wenchuan earthquake--cherish now, Thanksgiving life "multiple backpack template"

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.