/* Poj 1276 the meaning of multiple knapsack questions is probably given a currency m to be raised, given the number of currencies owned N [I] and the value V [I], q: How much can you raise is a multi-backpack problem DP [J] indicates the maximum number of valuable items that a backpack with a capacity of J can hold. Generally, the solution to multiple backpacks is to convert them. complete backpack and 01 backpack for Solution Code As follows: */# include <cstdio >#include <algorithm> using namespace STD; # define maxn 100005 # define INF 99999999int need, N; int DP [maxn]; int ans; struct node {int AM, V;} node [15]; void mut_pack (int I) {If (node [I]. am * node [I]. v> = need) // if the total value of an item is greater than required, it is converted into a full backpack problem {// while (1) {} For (Int J = node [I]. v; j <= need; j ++) {DP [J] = max (DP [J-node [I]. v] + node [I]. v, DP [J]); ans = DP [J]> ans? DP [J]: ans;} return;} int amout = node [I]. am; // printf ("% d \ n", amout); For (int K = 1; k <amout; amout-= K, K * = 2) // disassemble the package into 01 for (Int J = need; j> = K * node [I]. v; j --) {DP [J] = max (DP [J-K * node [I]. v] + K * node [I]. v, DP [J]); ans = DP [J]> ans? DP [J]: ans; // printf ("DP [% d]: % d \ n", J, ANS, DP [J]); // while (1) {}} for (Int J = need; j> = amout * node [I]. v; j --) {DP [J] = max (DP [J-amout * node [I]. v] + amout * node [I]. v, DP [J]); ans = DP [J]> ans? DP [J]: ANS ;}} int main () {// freopen ("in.txt", "W", stdout); While (scanf ("% d ", & amp; need, & amp; n )! = EOF) {for (INT I = 1; I <= N; I ++) scanf ("% d", & node [I]. am, & node [I]. v); For (INT I = 1; I <= need; I ++) DP [I] = 0; DP [0] = 0; ans = 0; for (INT I = 1; I <= N; I ++) mut_pack (I); printf ("% d \ n", ANS );}}