Dollars - UVa 147 dp
来源:互联网 发布:开源图像识别算法 编辑:程序博客网 时间:2024/05/22 17:45
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.202.000.00
Sample output
0.20 4 2.00 293
思路:首先是dp方程,看题解就好,其次我想说一个精度问题。刚刚试了一下ceil(),floor()和强转(int)的区别。后两者是一样的,ceil是向上取整,floor是向下取整,能够识别是精度是在1*10-16,比如2.99 三者转完是 3 2 2,但2.9999999999999999(共16个9)却是3 3 3。还有就是写法的问题,可以随机应变。
AC代码如下:
#include<cstdio>#include<cstring>#include<cmath>using namespace std;int num[11]={1,2,4,10,20,40,100,200,400,1000,2000};long long dp[6010];int main(){ int n,i,j,k,len1,len2,a,b; double p; dp[0]=1; for(i=0;i<=10;i++) for(j=num[i];j<=6000;j++) dp[j]+=dp[j-num[i]]; while(true) { scanf("%d.%d",&a,&b); k=(a*100+b)/5; if(k==0) break; if(b>=10) printf("%3d.%d",a,b); else printf("%3d.0%d",a,b); printf("%17lld\n",dp[k]); }}
- Dollars - UVa 147 dp
- UVA 147 Dollars (DP)
- uva--147Dollars +dp
- uva 147 Dollars 简单dp
- Uva 147-Dollars(DP)
- uva 147 Dollars(DP)
- uva 147 Dollars (dp)
- uva 147 Dollars (dp + 完全背包)
- UVA 147 Dollars 基础DP(水)
- UVa 147 Dollars(DP完全背包)
- UVa 147 Dollars(DP完全背包)
- UVA 147 Dollars (子集和问题 & DP)
- Dollars+uva+简单dp
- UVA 147- Dollars(dp之子集和问题)
- UVA 147 - Dollars
- uva 147 Dollars
- uva 147 Dollars
- UVa 147Dollars
- 再说中国剩余定理、扩展欧几里德与同余方程组
- poj3368--Frequent values(RMQ)
- tesseract-ocr3.02字符识别过程操作步骤
- 设计模式学习笔记之命令模式
- Google 搜索备用地址
- Dollars - UVa 147 dp
- epoll底层细节
- 01背包之(数之组合)
- 半年记
- CSU oj 1322: ZZY‘s new company
- 杭电ACM2016首字母变大写----20140726
- LINK : fatal error LNK1123: failure during conversion to COFF: file invalid
- git 查看 远程分支 本地分支
- OC---oc基础入门