Hdu2191 _ mourning for the victims of the 512 Wenchuan earthquake-Cherish the present and live a grateful life (Backpack/multiple backpacks)

Source: Internet
Author: User

Solution report

Question Portal

Question:

Not to mention Chinese;

Ideas:

Multiple basic backpacks. You can select multiple items for each item and convert them to 01.

#include <iostream>#include <cstring>#include <cstdio>#define inf 99999999using namespace std;int main(){    int t,i,j,n,m,v,p,h,cc,w[1010],c[1010],dp[1010];    scanf("%d",&t);    while(t--) {        int cnt=0;        memset(dp,0,sizeof(dp));        scanf("%d%d",&n,&m);        for(i=1; i<=m; i++) {            scanf("%d%d%d",&p,&h,&cc);            for(j=1; j<=cc; j++) {                w[++cnt]=p;                c[cnt]=h;            }        }        for(i=1; i<=cnt; i++) {            //printf("%d %d\n",w[i],c[i]);            for(j=n; j>=w[i]; j--) {                dp[j]=max(dp[j],dp[j-w[i]]+c[i]);            }        }        printf("%d\n",dp[n]);    }    return 0;}

Mourning for the victims of the 512 Wenchuan earthquake-Cherish the present and be grateful for your life Time Limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 14359 accepted submission (s): 6040


The Problem description is urgent! There is still a shortage of food in the disaster area!
In order to save the lives of compatriots in the disaster area, you are prepared to purchase food to support them. Now, suppose you have a total of N yuan, and the market has m kinds of rice, each type of rice is a bagged product, and its price varies, and can only be purchased in the whole bag.
Excuse me: How many kilograms of food can you purchase with limited funds?

Postscript:
Life is a life process full of variables. Natural disasters, man-made disasters, and pain are unpredictable threats in our life journey.
The future is unknown to us because the moon is full and the moon is full of hardships and sorrows. So what we need to do is to cherish the present and be grateful for our lives --
Thanks to our parents, they gave us life and raised us adults;
Thanks to the teachers, they taught us knowledge and taught us how to behave.
Thanks to our friends, they make us feel the warmth of the world;
Thanks to our competitors, they have made us enterprising and hard.
We also want to thank the wealth that the pain and hardships have brought us ~


 
Input data first contains a positive integer c, indicating that there are C test cases. The first line of each test case is two integers n and M (1 <= n <= 100, 1 <= m <= 100), indicating the amount of funds and the type of rice, followed by m rows of data, each row contains 3 numbers P, H and C (1 <= P <= 20, 1 <= H <=, 1 <= C <= 20 ), the price of each bag, the weight of each bag, and the number of bags of the corresponding rice.
Output for each group of test data, please output the maximum weight of the rice that can be purchased. You can assume that the cost is not only for all the rice, but you don't have to finish the cost. The output of each instance occupies one row.
Sample Input
18 22 100 44 100 2
 
Sample output
400
 
Authorlcy
Source2008-06-18 "ACM Program Design" Final Examination -- Sichuan come on! China!
Recommendlcy

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.