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 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

题意:经典问题,换钱。

精度呀马丹。打表速度可能快点。。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<limits.h>
typedef unsigned long long LL;
using namespace std;
#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )
#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )
#define CLEAR( a , x ) memset ( a , x , sizeof a )
int a[]={5,10,20,50,100,200,500,1000,2000,5000,10000};
LL dp[300100];
int n;
int main()
{
    double x;
    while(~scanf("%lf",&x)&&x!=0)
    {
        n=(int)(x*100+0.5);//+0.5注意精度
//        cout<<"23333   "<<n<<endl;
        memset(dp,0,sizeof(dp));
        dp[0]=1;
        REP(i,11)//对于每一种货币考虑加入到j中
        {
            REPF(j,a[i],n)
               dp[j]+=dp[j-a[i]];
        }
        printf("%6.2f%17lld\n",x,dp[n]);
    }
}

时间: 2024-12-19 17:21:44

UVA 147 Dollars (DP)的相关文章

UVA - 147 - Dollars (集合上的动态规划)

UVA - 147 Dollars Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status 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

POJ 3181 Dollar Dayz &amp;&amp; Uva 147 Dollars(完全背包)

首先是 Uva 147:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=83 细心看完这题后发现还是完全背包,只不过需要对浮点数处理一下.即把所有硬币的面值都乘以100,化为整数,对输入的数据也作同样的处理,然后就是套完全背包的模板了,在输出时还要用格式和精度来卡一卡你……一开始我没想到用printf可以的,于是百度了cout的输出格式控制,

UVA 1371 - Period(DP)

6.4 一些说明 数据属性可以重写同名的方法属性.这是为了避免在大型系统中产生问题的意外名称冲突.所以用一些减少冲突的常用方法是很有效果的.常用的方法包括:大写字母方法名称,用唯一的字符串来做为数据属性的名称(可以是个下划线_)或者用动词命名方法和用名字命名数据属性. 数据属性就像和对象的普通用户一样可以被方法引用.换句话说,类不能用来实现纯净的数据类型.事实上,在python中不能强制数据隐藏,一切基于约定.(另一方面,如C中写的,python的实现可以做到完全隐藏实现细节并且在必要是可以控制

UVA 1543 - Telescope(dp+几何)

题目链接:1543 - Telescope 题意:按顺序给定圆周上一些点,问用选一些点组成m边形面积的最大值. 思路:dp,dp[i][j][k] 表示第一个点为i,最后一个点为j,当前选择k的最大值,因为多选一个点,会多的面积为他和第一个点和最后一个点构成的三角形面积,然后利用海伦公式求面积,状态转移为:dp[i][j][x] = max(dp[i][j][x], dp[i - 1][j][k] + s); 代码: #include <stdio.h> #include <string

uva 104 Arbitrage (DP + floyd)

uva 104 Arbitrage Description Download as PDF Background The use of computers in the finance industry has been marked with controversy lately as programmed trading – designed to take advantage of extremely small fluctuations in prices – has been outl

uva 10271 Chopsticks (DP)

uva 10271 ChopsticksA 题目大意:给出客人数K和筷子数量N(支),总人数M=客人数K + 8(还有家人).要找出M组筷子,每组包括3支筷子,每组都有一个badness值,badness值为每组中较小的两支筷子的差值.求怎样分组,才能使总差值最小. 解题思路:dp[i][j]表示使用第i支筷子,并已组成j组是的最小badness总值.在取筷子时,要注意在所有未被使用的筷子中,要有比选取的两根筷子更长的筷子. #include <cstdio> #include <cst

【UVa】Jump(dp)

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4198 约瑟夫变形 根据f(n)=(f(n-1)+m)%n 因为是求倒数第几个 那么我们只要求出f(倒数第几个)的值然后再带进去即可. (没理解的自行面壁..) 而f(倒数第几个)=(m-1)%倒数第几个 然后就行了.. #include <cstdio> #include <

UVA - 1498 Activation (DP+概率)

Description After 4 years' waiting, the game "Chinese Paladin 5" finally comes out. Tomato is a crazy fan, and luckily he got the first release. Now he is at home, ready to begin his journey. But before starting the game, he must first activate

Uva 10465-Homer Simpson(DP)

题目链接:点击打开链接 DAG上的最长路. 题意:相当于给两种硬币的面值,每种可以用无限次,问恰好组成S 最多能用多少个硬币.如果不能恰好组成S,输出最大能组成的面值x(x<S)所需的最大硬币数 和 S-x. #include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include <string> #include <cctype&