"The main topic"
Given the face value and quantity of some banknotes, ask how many banknotes are required to make up the value C at least?
1 /*Dp[i][j]=mi (dp[i-1][j]≥0, that is, the first i-1 species can reach the number J)2 3 =-1 (J<ai or dp[i][j-ai]≤0, that is, plus a number I can not reach J or current and less than the current number)4 5 =dp[i][j-ai]-1 (can be achieved in the case)6 */7#include <iostream>8#include <cstdio>9#include <cstring>Ten using namespacestd; One Const intmaxn= -; A intA[MAXN]; - intM[MAXN]; - intdp[100000+5]; the intn,k; - - intMain () - { +scanf"%d%d",&n,&k); - for(intI=1; i<=n;i++) scanf ("%d",&a[i]); + for(intI=1; i<=n;i++) scanf ("%d",&m[i]); Amemset (dp,-1,sizeof(DP)); atdp[0]=0; - for(intI=1; i<=n;i++) - for(intj=0; j<=k;j++) - { - if(dp[j]>=0) dp[j]=M[i]; - Else in { - if(J<a[i] | | dp[j-a[i]]<=0) dp[j]=-1; to Elsedp[j]=dp[j-a[i]]-1; + } - } theprintf"%d", N-dp[k]); *}
"Multi-pack" bzoj1565-banknotes