https://vjudge.net/problem/POJ-1276
Test instructions
To a maximum amount of cash, existing n denominations of banknotes, the first I banknotes have NI Zhang, the value of Di. Ask for the maximum amount of money that can be pooled with these notes, and ask for no more than cash.
Analysis
Multiple knapsack problem. The di here is value and cost. Template questions
#include <iostream>#include<cmath>#include<cstring>#include<queue>#include<vector>#include<cstdio>#include<algorithm>#include<map>#include<Set>#defineRep (i,e) for (int i=0;i< (e); i++)#defineREP1 (i,e) for (int i=1;i<= (e); i++)#defineREPX (i,x,e) for (int i= (x); i<= (e); i++)#defineX First#defineY Second#definePB push_back#defineMP Make_pair#defineMset (Var,val) memset (Var,val,sizeof (VAR))#defineSCD (a) scanf ("%d", &a)#defineSCDD (A, b) scanf ("%d%d", &a,&b)#defineSCDDD (a,b,c) scanf ("%d%d%d", &a,&b,&c)#definePD (a) printf ("%d\n", a)#defineSCL (a) scanf ("%lld", &a)#defineSCLL (A, b) scanf ("%lld%lld", &a,&b)#defineSclll (a,b,c) scanf ("%lld%lld%lld", &a,&b,&c)#defineIOS Ios::sync_with_stdio (false); Cin.tie (0)using namespaceStd;typedefLong Longll;template<classT>voidTest (T a) {cout<<a<<Endl;} Template<classTclassT2>voidTest (T a,t2 b) {cout<<a<<" "<<b<<Endl;} Template<classTclassT2,classT3>voidTest (T a,t2 b,t3 c) {cout<<a<<" "<<b<<" "<<c<<Endl;} Template<classT>inlineBOOLScan_d (T &ret) { CharCintSGN; if(C=getchar (), c==eof)return 0; while(c!='-'&& (c<'0'|| C>'9')) c=GetChar (); SGN= (c=='-')?-1:1; RET= (c=='-')?0:(C-'0'); while(C=getchar (), c>='0'&&c<='9') ret = ret*Ten+ (C-'0'); RET*=SGN; return 1;}//const int N = 1E6+10;Const intINF =0x3f3f3f3f;Constll INF =0x3f3f3f3f3f3f3f3fll;Constll mod =1000000000;intT;voidtestcase () {printf ("Case %d:",++T);}Const intMAXN = 5e5+Ten ;Const intMAXM = -;Const DoubleEPS = 1e-8;Const DoublePI = ACOs (-1.0);intn,v;intdp[100005];intn[ the],d[ the];voidZeroonepack (intCintW) { for(inti=v;i>=c;i--) {Dp[i]=max (dp[i],dp[i-c]+W); }}voidCompletepack (intCintW) { for(inti=c;i<=v;i++) {Dp[i]=max (dp[i],dp[i-c]+W); }}voidMultiplepack (intCintWintm) { if(c*m>=V) {Completepack (c,w); }Else{ intk=1; while(k<m) {Zeroonepack (k*c,k*W); M=m-K; K<<=1; } zeroonepack (M*c,m*W); }}intMain () {#ifdef LOCAL freopen ("In.txt","R", stdin);#endif //LOCAL while(~SCANF ("%d",&V)) {scanf ("%d",&N); for(intI=1; i<=n;i++) {scanf ("%d%d",&n[i],&D[i]); } if(n==0|| v==0) {puts ("0"); Continue; } mset (DP,0); for(intI=1; i<=n;i++) {multiplepack (d[i],d[i],n[i]); } cout<<dp[V]<<Endl; } return 0;}
POJ-1276 Cash Machine (multiple backpack)