Hdu 2191 Mourning 5,124 Sichuan Wenchuan earthquake victims--now Bao, Thanksgiving life

Source: Internet
Author: User

Tribute to the 5,124 Sichuan Wenchuan earthquake victims-now treasure, Thanksgiving lifeTime limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)Total Submission (s): 14086 Accepted Submission (s): 5921

problem DescriptionTokyu 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 if you have a common capital of N yuan, and the market has m species of rice, each rice is bagged products, its price range. And only can buy the whole bag.


Excuse me: How many kilograms of grain can you buy 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 is an unknown for us. So, what we should do is to cherish now, Thanksgiving life-
Thank the parents, they give us life, raise our adult;
Thank the teacher. They grant us knowledge. Teach us how to behave
Thanks for your friends. They make us feel the warmth of the world;
Thanks to the opponent. They make us keep making progress and striving.
The same, we also want to thank the pain and hardship brought us wealth ~


 
InputThe input data first consists of a positive integer c, which indicates a C test case. The first line of each test sample is two integers n and m (1<=n<=100, 1<=m<=100), each representing the amount of money and the type of rice, followed by the M-row data, each line comprising 3 numbers p,h and C (1<=p<=20,1<= H&LT;=200,1&LT;=C&LT;=20), indicating the price per bag, the weight of each bag and the number of bags of the corresponding type of rice.


Output for each set of test data, please output the maximum weight that can be purchased for rice. You can buy not just all the rice if you fund it. And you'll be able to run out of money. The output of each instance takes up one row.


Sample Input

18 22 100 44 100 2
 
Sample Output
400
 idea: multiple backpacks converted to 01 backpacks.
<span style= "FONT-SIZE:18PX;" > #include <stdio.h> #include <iostream> #include <algorithm> #define M 1000005using namespace std; int dp[m],v[m],p[m];int max (int x,int y) {return (x>y?x:y);} int main () {int t,n,m,a,b,c,l;int i,j;cin>>t;while (t--) {l=0;cin>>n>>m;memset (v,0,sizeof (v));                memset (P,0,sizeof (P)); for (i=0;i<m;i++) {cin>>a>>b>>c;while (c--)    {v[l]=a;p[l]=b;l++;}} Memset (Dp,0,sizeof (DP)); for (i=0;i<l;i++) for (j=n;j>=v[i];j--) Dp[j]=max (Dp[j],dp[j-v[i]]+p[i]);cout< <dp[n]<<endl;} return 0;} </span>


Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

Hdu 2191 Mourning 5,124 Sichuan Wenchuan earthquake victims--now Bao, Thanksgiving life

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.