uva147 Dollars(完全背包方案)
来源:互联网 发布:剑雨逍遥手游进阶数据 编辑:程序博客网 时间:2024/06/18 14:21
Description
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
算精度时,要用一个极小数调整,循环时用极大值,用转换后的int值可能会T;
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 30010;
typedef long long LL;
LL k[N], dp[N];
int main()
{
int v[]={5,10,20,50,100,200,500,1000,2000,5000,10000};
double m;
while(scanf("%lf", &m)!=EOF&&m!=0.00)
{
memset(dp,0,sizeof(dp));
int n=(int)(m*100+0.001);
for(int i=0;i<=n;i++)
{
k[i]=1;
}
for(int i=0;i<=10;i++)
{
for(int j=v[i];j<=N;j++)
{
if(dp[j]<dp[j-v[i]]+v[i])
{
k[j]=k[j-v[i]];
}
else if(dp[j]==dp[j-v[i]]+v[i])
{
k[j]+=k[j-v[i]];
}
dp[j]=max(dp[j],dp[j-v[i]]+v[i]);
}
}
printf("%6.2f%17lld\n",m, k[n]);
}
return 0;
}
- uva147 Dollars(完全背包方案)
- uva147 - Dollars(完全背包)
- 完全背包问题UVA147
- B - Dollars (完全背包)
- UVA147- Dollars
- 【UVA147】【 Dollars】
- UVa147 Dollars
- uva147 - Dollars-------水题(精度注意)
- UVA147 完全背包DP(坑爹精度题)
- uva 147 Dollars(完全背包)
- UVa 147 Dollars(DP完全背包)
- UVa 147 Dollars(DP完全背包)
- UVA - 147 Dollars(完全背包)
- UVA 147 Dollars(完全背包)
- UVA 147 Dollars (完全背包)
- UVA 147 Dollars(完全背包)
- UVA 147 Dollars ( 完全背包+求解方案数精度问题)
- [动态规划]UVA147 - Dollars
- android-TableLayout布局中几个参数的作用
- 3.45
- Android : HttpURLConnection
- Android EditText inputType与numeric属性设置
- 重绘Activity 方法
- uva147 Dollars(完全背包方案)
- jmeter body data,输入中文显示为乱码,如何解决
- c++ string使用c_str转换成const char*
- leetcode 69. Sqrt(x)
- unity3d的学习
- 巴蜀 1738
- 单应性矩阵及其SVD求解
- Mybatis3.x与Spring4.x整合+代码自动生成
- 包装类型,演示Integer