The total weight of up to k items selected for N items cannot exceed W
Because each item has only one transfer order
For (INT I = 0; I <n; I ++)
For (Int J = W; j> = B [I]; j --)
For (int l = 1; L <= K; l ++)
Ensures that only one item is placed once.
# Include <stdio. h> # include <string. h> # include <stdlib. h> # include <string> # include <iostream> # include <algorithm> # include <sstream> # include <math. h> using namespace STD; # include <queue> # include <stack> # include <vector> # include <deque> # include <set> # include <map> # define CLer (ARR, Val) memset (ARR, Val, sizeof (ARR) # define in freopen ("in.txt", "r", stdin); # define out freopen ("out.txt", "W ", stdout); typedef long ll; const int maxn = 1000006; // maximum number of points const int maxm = 20006; // maximum number of sides const int INF = 1101521204; const int mod = 1000000007; int DP [23] [1211], a [1111], B [1111]; int main () {int N, T, M, K, w; // In; scanf ("% d", & T); While (t --) {CLer (DP, 0); scanf ("% d ", & N, & K); For (INT I = 0; I <n; I ++) scanf ("% d", & A [I], & B [I]); scanf ("% d", & W); For (INT I = 0; I <n; I ++) for (Int J = W; j> = B [I]; j --) for (INT L = 1; L <= K; l ++) DP [l] [J] = max (DP L-1] [J-B [I] + A [I], DP [l] [J]); printf ("% d \ n", DP [k] [W]);}
[DP] HDU 2660 accepted neck133 limits backpack