本文共 1506 字,大约阅读时间需要 5 分钟。
New Zealand currency consists of $100, $50, $20, $10, and $5notes and $2, $1, 50c, 20c, 10c and 5c coins. Write a program thatwill determine, for any given amount, in how many ways that amount maybe 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 will consist of a series of real numbers no greater than $300.00each on a separate line. Each amount will be valid, that is will be amultiple of 5c. The file will be terminated by a line containing zero(0.00).
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 placesand right justified in a field of width 6), followed by the number ofways in which that amount may be made up, right justified in a fieldof width 17
0.202.000.00
0.20 4 2.00 293
题目大意:
给定11种面值分别为$100, $50, $20, $10, and $5 notes and $2, $1, 50c, 20c, 10c and 5c coins的钱,现在给定一个钱数,求出可以组成的种类数。
代码实现:
#include#include #include #define MAX 999999using namespace std;long long dp[MAX];int n,arr[20]={5,10,20,50,100,200,500,1000,2000,5000,10000};int main(){ int i,j,k; double t; while(cin>>t) { if(t==0.00)break; n=(t+0.005)*100; memset(dp,0,sizeof(dp)); dp[0]=1; for (i = 0; i <= 10; i++) for (j = 0; j <= n; j++) dp[j+arr[i]] += dp[j]; cout< < < <<" "< <
转载地址:https://blog.csdn.net/u010368749/article/details/19898169 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!