# Include <iostream> # include <cstdio> # include <algorithm>/* although this question cannot be sorted, however, I think it is more reasonable to buy the largest price and weight first */# include <cstring> # include <string> using namespace STD; # define n 105int DP [N]; struct node {int P, h, C;} num [105]; bool CMP (node A, Node B) {return. H * B. p>. p * B. h;} int main (void) {int n, m; int I, j, k; int C; CIN> C; while (c --) {CIN> N> m; for (I = 1; I <= m; I ++) CIN> num [I]. p> num [I]. h> num [I]. c; sort (Num + 1, num + m + 1, CMP); memset (DP, 0, sizeof (DP); for (I = 1; I <= m; I ++) for (k = 1; k <= num [I]. c; k ++) {for (j = N; j> = num [I]. p; j --) {DP [J] = max (DP [J], DP [J-num [I]. p] + num [I]. h) ;}} cout <DP [N] <Endl ;}return 0 ;}
HDU 2191 mourns the victims of the 512 Wenchuan earthquake-Cherish the present and be grateful for your life (multiple backpacks)