UVA147——DP——Dollars

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.20
2.00
0.00

Sample output

  0.20                4
  2.00              293大意:同UVA647 double转换成int为什么要加0.5.....

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long  dp[30005][15];
int v[11] = {5,10,20,50,100,200,500,1000,2000,5000,10000};
long long  DP(long long  i,long long  j)
{
    if(dp[i][j] != -1)
        return dp[i][j];
    dp[i][j] = 0;
    for(int k = 0 ; i-k*v[j] >= 0; k++)
        dp[i][j] += DP(i-k*v[j],j-1);
    return dp[i][j];
}
int main()
{
    memset(dp,-1,sizeof(dp));
    double n;
    while(~scanf("%lf",&n)){
        if(n == 0.00)
            break ;
      int  m =(int)(n*100+0.5);
        for(long long  i = 0 ; i <= m; i++)
            dp[i][0] = 1;
            printf("%6.2f%17lld\n",n,DP(m,10));
    }
    return 0;
}

 
时间: 2024-11-03 15:40:14

UVA147——DP——Dollars的相关文章

uva147 - Dollars(完全背包)

题目:uva147 - Dollars(完全背包) 题目大意:给出11种硬币,然后给出一个数字,问可以有多少方式由上面的给的硬币凑出.这里要注意精度误差,题目可能会给出20.005这样的数据,虽然我觉得这是不合法的数据,但是但是会给,并且还需要你向上取整. 解题思路:完全背包. 代码: #include <cstdio> #include <cstring> const int N = 11; const int maxn = 30005; const int c[N] = {5,

Dollars(简单DP)

J - Dollars Time Limit:3000MS    Memory Limit:0KB    64bit IO Format:%lld & %llu SubmitStatus Description  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 d

UVA 147 Dollars (DP)

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

UVA 1412 - Fund Management(用vector容器模拟状态的状压dp)

Frank is a portfolio manager of a closed-end fund for Advanced Commercial Markets (ACM ). Fund collects money (cash) from individual investors for a certain period of time and invests cash into various securities in accordance with fund's investment

BNUOJ 17286 Dollars

Dollars Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVA. Original ID: 14764-bit integer IO format: %lld      Java class name: Main New Zealand currency consists of $100, $50, $20, $10, and $5 notes and $2, $1, 50c, 20c, 1

hdu3669之二维斜率DP

Cross the Wall Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 327680/327680 K (Java/Others) Total Submission(s): 4176    Accepted Submission(s): 748 Problem Description "Across the Great Wall, we can reach every corner in the world!" No

ASC(1)C(树形DP)

New Year Bonus Grant Special JudgeTime Limit: 6000/3000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) SubmitStatisticNext Problem Problem Description All programmers of Mocrosoft software company are organized in a strict subordination hi

HDU 3366 Passage (概率DP)

Passage Problem Description Bill is a millionaire. But unfortunately he was trapped in a castle. There are only n passages to go out. For any passage i (1<=i<=n), Pi (0<=Pi<=1) denotes the probability that Bill will escape from this castle saf

个人专题训练——背包dp(持续更新中)

A - Proud Merchants   HDU - 3466(带限制的01背包) 题意: 给你m元,去买大米,每袋大米给你p,q,v 当你手中的钱 >= q时,才能买价格为p的这袋大米,它的价值是v,求最大价值. 01背包的转移方程根据题意很容易写出来,但是会有问题. for (int i = 1; i <= n; ++i) for (int j = m; j >= q[i]; --j) dp[j] = max(dp[j], dp[j - p[i]] + v[i]);考虑到了可能存在