#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. Hibernate4 执行存储过程

    Hibernate3.3.2版本中getSession().connection()已被弃用,hibernate4中官方推荐使用Session doWork()方法进行jdbc操作 当Hibernat ...

  2. 批量删除wordpress垃圾评论留言

    wordpress博客的存在,垃圾评论注定会找上门来.大家还可以用Akismet.Bad Behavior.Spam Karma等一些其他的插件或者直接用程序写个验证码函数对留言进行验证来过滤 垃圾评 ...

  3. 支持高并发的IIS Web服务器常用设置 II

    适用的IIS版本:IIS 7.0, IIS 7.5, IIS 8.0 适用的Windows版本:Windows Server 2008, Windows Server 2008 R2, Windows ...

  4. java笔记--使用事件分配线程更新Swing控件

    使用事件分配线程更新Swing控件: Swing并不是线程安全的,如果在多个线程中更新Swing控件,则很可能造成程序崩溃. 为了避免这种问题,可以使用时间分配线程来更新Swing控件. EventQ ...

  5. HDU 4858 项目管理(邻接表 暴力模拟)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4858 我们建造了一个大项目!这个项目有n个节点,用很多边连接起来,并且这个项目是连通的! 两个节点间可 ...

  6. NGUI之scroll view制作,以及踩的坑总结

    http://blog.csdn.net/monzart7an/article/details/23878505 链接: http://game.ceeger.com/forum/read.php?t ...

  7. Linux Apache 怎么修改工作模式

    Apache默认为prefork模式,主要是考虑到稳定性的原因. 要切换到worker模式,则需要登录到linux上,进行如下操作: 进入/usr/sbin目录 cd /usr/sbin 将当前的pr ...

  8. [ruby on rails] 跟我学之(5)显示所有数据

    之前的index页,显示的是hello world,现在将其修改为显示我们在rails console里面录入的数据. 1. 修改action 如之前的章节<[ruby on rails] 跟我 ...

  9. CSS3弹性盒模型flexbox完整版教程

    http://caibaojian.com/flexbox-guide.html 来自CSS Tricks上的一个教程,原文为:A Complete Guide to Flexbox.文中详细的介绍了 ...

  10. linux awk 内置函数详细介绍(实例)

    这节详细介绍awk内置函数,主要分以下3种类似:算数函数.字符串函数.其它一般函数.时间函数 一.算术函数: 以下算术函数执行与 C 语言中名称相同的子例程相同的操作: 函数名 说明 atan2( y ...