For example, if we have 11 cents, then we can make changes with one 10-cent coin and one 1-cent coin, or two 5-cent coins and one 1-cent coin, or one 5-cent coin and six 1-cent coins, or eleven 1-cent coins. So there are four ways of making changes for 11 cents with the above coins. Note that we count that there is one way of making change for zero cent.
Write a program to find the total number of different ways of making changes for any amount of money in cents. Your program should be able to handle up to 100 coins.
11 26
4 13
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<string.h>
using namespace std;
int main( )
{
int a, b, c, d, e, i, n, num;
while (scanf("%d", &n) != EOF)
{ num = 0;
for (a = 0; a <= n; a++)
for (b = 0; 5*b <= n-a; b++)
for (c = 0; 10*c <= n-a-b*5; c++)
for (d = 0; 25*d <= n-a-b*5-c*10; d++)
{
e = n-a-b*5-c*10 - 25*d;
if(e%50==0 && a+b+c+d+e/50 <= 100)//注意这里的e要除与50啊!!,第一次wa就是这里错。
num++;
}
cout << num <<endl;
}
return 0;
}
暴力枚举解决。