2191 Mourning 512 Wenchuan earthquake--cherish now, Thanksgiving life (multi-pack water)

Source: Internet
Author: User
Tags mul

Input
The 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),
The amount of money and the type of rice, then the M-row 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, output 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
1
8 2
2 100 4
4 100 2


Sample Output

400


Fruit problem

#include <iostream> #include <cstdio> #include <cstring>using namespace Std;int v,n;int p[110],w[110] , C[110];int Dp[110];int Main () {    int _;    scanf ("%d", &_);    while (_--) {        scanf ("%d%d", &v,&n);        Memset (Dp,0,sizeof (DP));        for (int i=1;i<=n;i++) scanf ("%d%d%d", &p[i],&w[i],&c[i]);        for (int i=1;i<=n;i++) {for            (int k=1;c[i]>0;k<<=1) {                int mul=min (k,c[i]);                for (int j=v;j>=p[i]*mul;j--) Dp[j]=max (Dp[j],dp[j-p[i]*mul]+w[i]*mul);                C[i]-=mul;            }        }        printf ("%d\n", Dp[v]);    }    return 0;}


2191 Mourning 512 Wenchuan earthquake--cherish now, Thanksgiving life (multi-pack water)

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.