Dollars
Dollars |
New Zealand currency consists of $100, $50, $20, $10, and $5 notes and $2, $1, 50c, 20c, 10c and 5c coins. Write a program that will determine, for any given amount, in how many ways that amount may be made up. Changing the order of listing does not increase the count. Thus 20c may be made up in 4 ways: 1 20c, 2 10c, 10c+2 5c, and 4 5c.
Input
Input will consist of a series of real numbers no greater than $300.00 each on a separate line. Each amount will be valid, that is will be a multiple of 5c. The file will be terminated by a line containing zero (0.00).
Output
Output will consist of a line for each of the amounts in the input, each line consisting of the amount of money (with two decimal places and right justified in a field of width 6), followed by the number of ways in which that amount may be made up, right justified in a field of width 17.
Sample input
0.20 2.00 0.00
Sample output
0.20 4 2.00 293
题意:
纽西兰的货币包含了$100, $50, $20, $10, $5 的纸钞和$2, $1, 50c, 20c, 10c, 5c 的硬币。给你某金额的数字,请你写一个程式回答:使用这些面额的纸钞或硬币,有多少种不同的方法可以组合成这个金额。例如:20c 可以有4个方法可以得到:(改变金额的顺序不会增加方法数,例如2 * 5c + 1 * 10c 和下面第3种方法视为同一种)
- 1 * 20c
- 2 * 10c
- 1* 10c + 2 * 5c
- 4 * 5c
#include<iostream>
#include<cstring>
#include<iomanip>
using namespace std;
const int maxn=30100;
int d[12]={0,10000,5000,2000,1000,500,200,100,50,20,10,5};
long long dp[maxn];
int main()
{
int x,y;
char ch;
while(cin>>x>>ch>>y)
{
int val=x*100+y;
if(val==0) break;
memset(dp,0,sizeof(dp));
dp[0]=1;
int i,j,k;
for(i=1;i<=11;i++)
{
for(j=d[i];j<=val;j++)
{
dp[j]=dp[j]+dp[j-d[i]];
}
}
double dval=val/100.0;
cout<<setiosflags(ios::right)<<setw(6)<<fixed<<setprecision(2)<<dval;
cout<<setiosflags(ios::right)<<setw(17)<<dp[val]<<endl;
}
return 0;
}