【解题报告】uva147_Dollars(美元, dp, 完全背包)
来源:互联网 发布:淘宝店被降权怎么办 编辑:程序博客网 时间:2024/06/06 17:51
147 - Dollars
Time limit: 3.000 secondsDollars
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.202.000.00
Sample output
0.20 4 2.00 293
题目大意:
给出11种面值的硬币($100, $50, $20, $10, and $5 notes and $2, $1, 50c, 20c, 10c and 5c coins),每次输入一个金额,以元为单位,求用所给硬币组合出该金额共有多少种组合方案,硬币的顺序不影响方案数量。
解题思路:
将所有面值的硬币与输入金额转化为统一的度量单位——分,即可看成完全背包问题。
定义状态d(i,j),代表用前i种硬币组合出金额j的方案数。
状态转移方程:d(i,j) = ∑ { d(i-1,j-k*c[i]) | 1<=k<=j/c[i], c[i]<=j }
#include <cstdio>#include <cstring>int c[11]={5,10,20,50,100,200,500,1000,2000,5000,10000};//硬币面额long long d[30010];int main(){ d[0]=1;//init for(int i=0;i<11;++i){//枚举11种硬币, for(int j=c[i];j<=30000;++j){//升序枚举所有金额状态 d[j]+=d[j-c[i]]; } } double a; while(~scanf("%lf",&a),a){ int A=int(a*100+0.5);//扩大100倍,单位转换为分,注意要四舍五入 printf("%6.2lf%17lld\n",a,d[A]); } return 0;}
- 【解题报告】uva147_Dollars(美元, dp, 完全背包)
- 【解题报告】uva674_Coin Change(硬币找零, dp, 完全背包)
- 【解题报告】uva357_Let Me Count The Ways(让我来数数方案, dp, 完全背包)
- 背包问题 2 完全背包解题报告
- HDU 1114Piggy-Bank(完全背包) 解题报告
- HDU 1114 Piggy-Bank 解题报告(完全背包)
- 【解题报告】uva562_Dividing coins(划分硬币, dp, 01背包)
- 解题报告:POJ_1155 TELE 树型DP(树上01背包)
- CodeVS1025 选菜 解题报告【背包型DP】
- 蓝桥杯 历届试题 买不到的数目 解题报告(完全背包,数论)
- nyoj311 完全背包(dp)
- 完全背包(经典dp)
- 01背包、完全背包(DP)
- 最大报销额 (HDU 1864)解题报告(DP - 01 - 背包)
- 解题报告:HDU1011 Starship Troopers 树型DP(树上01背包)
- Codeforces815C Karen And SuperMarket 解题报告【树上DP/树上背包(?)】
- pku 2392 space elevator 多重背包 dp 解题报告
- Codeforces Round #300 A, B(背包dp), ..解题报告
- JSON 字符串 与 java 对象的转换
- 在估算时为什么要分解估算对象?
- 阿里巴巴笔试面试题
- STP协议的一些理解
- 奇偶数分离
- 【解题报告】uva147_Dollars(美元, dp, 完全背包)
- 机器学习算法-决策树ID3
- css3 @media ipad/iphone4/iphone5/ipad mini/ipad Retina
- struts2、jsp分页代码
- 黑马程序员----JAVA Socket编程
- vi查找替换命令详解
- Netty系列之Netty高性能之道
- 来自苹果的编程语言——Swift简介
- matlab中S-函数的建立与应用