Test instructions
There are n types of banknotes, each of which is known to have a par value and a quantity that can be made up to no more than the maximum total value of cash.
Analysis:
It's a shame that the problem has been written in the tle itself.
Find a relatively concise code copied over. poj1276
1#include <cstdio>2#include <cstring>3 4 Const intMAXN = A;5 Const intMAXP =100000+Ten;6 7 BOOLVIS[MAXP];//whether to reach the total face value I8 intUSED[MAXP];//The amount to be used for this type of note at the total face value I9 intA[MAXN], B[MAXN];//The amount and face value of each type of noteTen One intcash, N; A - intMain () - { the //freopen ("In.txt", "R", stdin); - - while(SCANF ("%d", &cash) = =1) - { +scanf"%d", &n); - for(inti =0; I < n; ++i) scanf ("%d%d", &a[i], &b[i]); + Amemset (Vis,false,sizeof(Vis)); atvis[0] =true; - for(inti =0; I < n; ++i) - { -memset (Used,0,sizeof(used)); - for(intj = B[i]; J <= Cash; ++j) - if(Vis[j-b[i] &&!vis[j] && Used[j-b[i] <A[i]) in{Vis[j] =true; USED[J] = Used[j-b[i]] +1; } - } to + for(inti = cash; I >=0; I.)if(Vis[i]) {printf ("%d\n", i); Break; } - } the * return 0; $}
code June
POJ 1276 (multiple backpack) Cash machine