Mourning for 512 Wenchuan earthquake--cherish now, Thanksgiving life
Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 16861 Accepted Submission (s): 7131
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 Input18 22 100 44 100 2
Sample Output400
Authorlcy
SOURCE2008-06-18 "ACM Program Design" Final Exam--Sichuan refueling! China Refueling!
#include <stdio.h>#include<string.h>#include<algorithm>using namespacestd;#defineINF 0x3f3f3fintt,n,m;intdp[ the];structrice{intp; intW; intnum;} r[ the];voidsolve () { for(intI=1; i<=m;i++) { for(intk=1; k<=r[i].num;k++) { for(intj=n;j>=r[i].p;j--) {Dp[j]=max (dp[j-r[i].p]+R[i].w,dp[j]); }}} printf ("%d\n", Dp[n]);}intMain () {scanf ("%d",&t); while(t--) {memset (DP,0,sizeof(DP)); scanf ("%d%d",&n,&m); for(intI=1; i<=m;i++) {scanf ("%d%d%d",&r[i].p,&r[i].w,&r[i].num); } solve (); } return 0;}
hdu2191 Mourning 512 Wenchuan earthquake--cherish now, Thanksgiving life (full backpack)