Question address: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1963
Find the maximum profit that can be obtained each time, multiple backpacks.
Here we will use a technique. The question "V [I]" is a multiple of 1000, so it can be divided by 1000.
The Code is as follows:
# Include <iostream> # include <cstdio> # include <cstdlib> # include <cmath> # include <cstring> # include <string> # include <vector> # include <list> # include <deque> # include <queue> # include <iterator> # include <stack> # include <map> # include <set> # include <algorithm> # include <cctype> using namespace STD; typedef long ll; const int n = 51510; const ll II = 1000000007; int DP [N], V [15], W [15]; int V, Y, N; int main () {int N, I, J, K, L, t; CIN> N; while (n --) {scanf ("% d ", & V, & Y, & T); for (I = 1; I <= T; I ++) {scanf ("% d ", & V [I], & W [I]); V [I]/= 1000 ;}for (L = 1; L <= y; l ++) {int temp = V/1000; memset (DP, 0, sizeof (DP); for (I = 1; I <= T; I ++) {for (j = V [I]; j <= temp; j ++) // multiple backpacks J = V [I]; j <= temp; j ++ // 01 backpack J = temp; j> = V [I]; J -- If (DP [J] <DP [J-V [I] + W [I]) DP [J] = DP [J-V [I] + W [I];} V + = DP [temp];} printf ("% d \ n ", v);} return 0 ;}