问题:设有1元、2元、5元、10元、20元的纸币各若干张,求出用这些纸币能够凑出多少种不同的钱数
输入每种面值的纸币数,输出不同钱数的个数。
输入样例:1 1 0 0 0;
输出样例:3;
#include#include #include #include #include #include using namespace std; int a[25],b[25]; bool yes[10005]; int Ans; void search(int k,int s) { //当前是在第k重循环 if (k>N) { if (yes[s]) { Ans++; yes[s]=false; } return; } for (int i=0; i<=a[k]; i++) search(k+1,s+i*b[k]); } int main() { memset(yes,true,sizeof(yes)); cin >> N; for (int i=1; i<=N; i++) cin >> b[i]; for (int i=1; i<=N; i++) cin >> a[i]; search(1,0); cout << Ans-1 <



