Title Link: https://vjudge.net/problem/POJ-1276
Test instructions: There are now cash, and n kinds of coins, each coin has NI, the value of Di, for all kinds of coins composed of not more than cash of the largest amount of money ....
Idea: binary split into 01 backpack, or converted to a full backpack are all possible
Full backpack:
//This problem can let w,v start from i=1 time, so f[0]=0, when cash=0 or n=0 direct output 0//define a num array to let it store the number of remaining#include<iostream>#include<cstring>using namespacestd;Const intmaxn= ++Ten;intCash,n;intW[MAXN],V[MAXN];intf[maxn* -],num[maxn* -];intMain () {Ios::sync_with_stdio (false); while(cin>>cash>>N) {memset (F,0,sizeof(f)); for(intI=1; i<=n;i++) {cin>>w[i]>>V[i]; } for(intI=1; i<=n;i++) {memset (num,0,sizeof(num)); for(intj=v[i];j<=cash;j++) { if(f[j]<f[j-v[i]]+v[i]&&num[j-v[i]]<W[i]) {F[j]=f[j-v[i]]+V[i]; NUM[J]=num[j-v[i]]+1; } }} cout<<f[cash]<<Endl; } return 0;}
poj1276 Cash Machine (full backpack template problem)