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 Input
18 22 100 44 100 2
Sample Output
400
#include <stdio.h> #include <string.h> #define MAXN 102int dp[maxn];int max (int a, int b) {return a > B? a : b; }int Main () {freopen ("Stdin.txt", "R", stdin), int T, N, M;int P, H, C;int I, j;scanf ("%d", &t), while (t--) {scanf ("%d% D ", &n, &m), memset (DP, 0, sizeof (DP)), while (m--) {scanf ("%d%d%d ", &p, &h, &c); for (i = 1; C C-= i, I <<= 1) {if (i > C) i = c;for (j = N; J >= I * P;--j) dp[j] = max (Dp[j], dp[j-i*p] + i * H);}} printf ("%d\n", Dp[n]);} return 0;}
HDU2191 Mourning 512 Wenchuan earthquake--cherish now, Thanksgiving life "multiple backpack"