#include<bits/stdc++.h>
using namespace std;
int main()
{
unsigned long long int dp[];
memset(dp,,sizeof(dp));
dp[]=;
for(int i=;i<=;i++)
for(int j=i;j<;j++)
dp[j]=dp[j]+dp[j-i];
int n;
while((scanf("%d",&n))!=EOF)
{
printf("%I64d\n",dp[n]);
}
return ;
return ;
}

这两道题基本思路是一样的,不过uva147的输出实在是个大坑,因为double的问题,所以考虑精度的损失。

代码中的输出部分被我注释掉的那一部分是错误的输出,格式什么的都是正确的,但是存在精度的损失。应该注意一下

hdu1284

Description

在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很多种兑法。请你编程序计算出共有多少种兑法。
 

Input

每行只有一个正整数N,N小于32768。
 

Output

对应每个输入,输出兑换方法数。
 

Sample Input

2934 12553
 

Sample Output

718831 13137761
 
 
#include<bits/stdc++.h>
using namespace std;
int main()
{
unsigned long long int dp[];
int money[]={,,,,,,,,,,};
memset(dp,,sizeof(dp));
dp[]=;
//cout<<money[10]<<endl;
for(int i=;i>=;i--)
{
for(int j=money[i];j<;j++) {
dp[j]=dp[j-money[i]]+dp[j];
}
}
//cout<<dp[0]<<dp[5]<<dp[10]<<dp[15]<<endl;
double n; //cin>>n;
//cout<<dp[5]<<endl;
//cout<<dp[10020]<<endl;
int a,b;
while((scanf("%d.%d",&a,&b))!=EOF&&a+b)
{
/* n=n*100;
cout<<n;
int m=n;
printf("%6.2lf%17I64d\n",n/100,dp[m]);*/
int n=a*+b;//cout<<n<<endl;
double ans=n*1.0/100.0;
printf("%6.2lf%17lld\n",ans,dp[n]);
} return ;
}
uva 147

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
 
dp[j]=dp[j]+dp[j-i],j表示钱数,i表示价值。首先i=1,这样得到不同的钱数被全部分为1的硬币的兑换法,然后把大于2的数分解为 2+i,即2+i的钱分为一个2加第i个钱全部
为1的分法,这么递推下去。

hdu 1284 分硬币 && uva 147的更多相关文章

  1. 专题复习--背包问题+例题(HDU 2602 、POJ 2063、 POJ 1787、 UVA 674 、UVA 147)

    *注 虽然没什么人看我的博客但我还是要认认真真写给自己看 背包问题应用场景给定 n 种物品和一个背包.物品 i 的重量是 w i ,其价值为 v i ,背包的容量为C.应该如何选择装入背包中的物品,使 ...

  2. hdu 1284完全背包

    http://acm.hdu.edu.cn/showproblem.php?pid=1284 New~ 欢迎“热爱编程”的高考少年——报考杭州电子科技大学计算机学院关于2015年杭电ACM暑期集训队的 ...

  3. hdu 1284 钱币兑换问题 完全背包

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1284 递推公式:dp[i] = sum(dp[i], dp[i-C]) /* 钱币兑换问题 Time ...

  4. HDU 1284 钱币兑换问题(全然背包:入门题)

    HDU 1284 钱币兑换问题(全然背包:入门题) http://acm.hdu.edu.cn/showproblem.php?pid=1284 题意: 在一个国家仅有1分,2分.3分硬币,将钱N ( ...

  5. HDU 1284 钱币兑换问题(普通型 数量无限的母函数)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1284 钱币兑换问题 Time Limit: 2000/1000 MS (Java/Others)    ...

  6. 题解报告:hdu 1284 钱币兑换问题(简单数学orDP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1284 Problem Description 在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很 ...

  7. HDU 1284 钱币兑换问题 母函数、DP

    题目链接:HDU 1284 钱币兑换问题 钱币兑换问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  8. POJ 3181 Dollar Dayz && Uva 147 Dollars(完全背包)

    首先是 Uva 147:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_p ...

  9. HDU 2098 分拆素数和

    HDU 2098 分拆素数和 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768K (Java/Others) [题目描述 ...

随机推荐

  1. VS的工程链接优化的问题

    打算在项目中试试 CATCH 这个测试框架.请同事在工程中进行了试验,结果却出现了一点问题. CATCH 和 GTest 之类的框架一样,可以直接在 C++ 文件中定义测试函数,就能自动地注册到测试列 ...

  2. DateTime季度的计算

    //获取本季度的第一天 DateTime.Now.AddMonths(0 - (DateTime.Now.Month - 1) % 3).ToString("yyyy-MM-01" ...

  3. cocos2d-x创建精灵动画方式汇总

    1.创建精灵框架缓存,并向其中添加相应的动画文件(plist),最后,通过动画集缓存生产动画 CCSpriteFrameCache *cache = CCSpriteFrameCache::share ...

  4. Unity中下载和本地保存实例

    原地址:http://www.linuxidc.com/Linux/2011-10/45888.htm Download.cs using UnityEngine; using System.Coll ...

  5. 在mac上安装nodejs

    文章转载自我的个人博客  www.iwangzheng.com node.js最初是2009年发布的,目标是为聊实现事件驱动和非阻塞I/O的web服务器,应用的场景非常的广泛,有web服务器.实时应用 ...

  6. Linux的watch命令 — 实时监测命令的运行结果

    Linux的watch命令 — 实时监测命令的运行结果 watch 是一个非常实用的命令,基本所有的 Linux 发行版都带有这个小工具,如同名字一样,watch 可以帮你监测一个命令的运行结果,省得 ...

  7. tcp ip detatils

    tcp ip detatils 8.关于TCP协议,下面哪种说法是错误的()A.TCP关闭连接过程中,两端的socket都会经过TIME_WAIT状态B.对一个Established状态的TCP连接, ...

  8. 如何让你的scrapy爬虫不再被ban之二(利用第三方平台crawlera做scrapy爬虫防屏蔽)

    我们在做scrapy爬虫的时候,爬虫经常被ban是常态.然而前面的文章如何让你的scrapy爬虫不再被ban,介绍了scrapy爬虫防屏蔽的各种策略组合.前面采用的是禁用cookies.动态设置use ...

  9. delphi 换行操作 Word

    delphi 换行操作 我将我的商用<旅行社管理系统>的 发团通知 部分奉献给您,望对您有所帮助. procedure TFrmMain.N327Click(Sender: TObject ...

  10. codeforces B. Sereja and Stairs 解题报告

    题目链接:http://codeforces.com/problemset/problem/381/B 题目意思:给定一个m个数的序列,需要从中组合出符合楼梯定义 a1 < a2 < .. ...