http://acm.hdu.edu.cn/showproblem.php?pid=5410
/* First 01 backpacks and then a full backpack *//************************************************* Author:P owatr* Created time:2015-8-20 19:46 : 35* File name:1005_1.cpp ************************************************/#include <cstdio> #include < algorithm> #include <iostream> #include <sstream> #include <cstring> #include <cmath># Include <string> #include <vector> #include <queue> #include <deque> #include <stack># Include <list> #include <map> #include <set> #include <bitset> #include <cstdlib> #include <ctime>using namespace std; #define Lson L, Mid, RT << 1#define Rson mid + 1, R, RT << 1 | 1typedef long ll;const int MAXN = 1e5 + 10;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;int A[MAXN], B[MAXN], C [Maxn];int Dp[maxn];int Main () {int T; int n, m; scanf ("%d", &t); while (t--) {scanf ("%d%d", &m, &n); memset (DP, 0, sizeof (DP)); for (int i = 1; I <= N i++) scanf ("%d%d%d", &a[i], &b[i], &c[i]); for (int i = 1; I <= n; i++) {for (int j = m; J >= A[i]; j--) dp[j] = max (Dp[j], dp[j-a[i]) + B[i] + c[i]); for (int j = a[i]; j <= M; j + +) Dp[j] = max (Dp[j], Dp[j-a[i]] + b[i]); } printf ("%d\n", Dp[m]); } return 0;}
hdu5410--01 backpack + Full backpack--CRB and his Birthday