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)