http://acm.hdu.edu.cn/showproblem.php?pid=2191
Chinese topic, do not say nonsense ...
Analysis: The problem is a multi-pack, but can be used 01 backpack to do, each kind of rice has a few bags a separate storage, so it becomes 01 backpack ...
#include <iostream>#include<stdio.h>#include<string.h>#include<string>#include<vector>#include<algorithm>#include<map>#include<queue>#include<stack>#include<math.h>using namespacestd;#defineMet (A, b) memset (A, B, sizeof (a))#defineMAXN 2500#defineINF 0x3f3f3f3fConst intMOD = 1e9+7; typedefLong LongLL;intDP[MAXN];structnode{intx, y;} S[MAXN];intMain () {intT, N, M, p, H, C; scanf ("%d", &T); while(T--) {scanf ("%d%d", &n, &m); intK =1; for(intI=1; i<=m; i++) {scanf (" %d%d%d", &p, &h, &c); for(intj=1; j<=c; J + +) {s[k].x=p; S[k++].y=h; }} memset (DP,0,sizeof(DP)); for(intI=1; i<k; i++) { for(intJ=n; j>=s[i].x; j--) {Dp[j]= Max (Dp[j], dp[j-s[i].x]+s[i].y); }} printf ("%d\n", Dp[n]); } return 0;}
View Code
Mourning for 512 Wenchuan earthquake--cherish now, Thanksgiving life hdu2191 (01 backpack)