hdu 1284 分硬币 && uva 147
#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
Input
Output
Sample Input
Sample Output
#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 ;
}
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
hdu 1284 分硬币 && uva 147的更多相关文章
- 专题复习--背包问题+例题(HDU 2602 、POJ 2063、 POJ 1787、 UVA 674 、UVA 147)
*注 虽然没什么人看我的博客但我还是要认认真真写给自己看 背包问题应用场景给定 n 种物品和一个背包.物品 i 的重量是 w i ,其价值为 v i ,背包的容量为C.应该如何选择装入背包中的物品,使 ...
- hdu 1284完全背包
http://acm.hdu.edu.cn/showproblem.php?pid=1284 New~ 欢迎“热爱编程”的高考少年——报考杭州电子科技大学计算机学院关于2015年杭电ACM暑期集训队的 ...
- hdu 1284 钱币兑换问题 完全背包
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1284 递推公式:dp[i] = sum(dp[i], dp[i-C]) /* 钱币兑换问题 Time ...
- HDU 1284 钱币兑换问题(全然背包:入门题)
HDU 1284 钱币兑换问题(全然背包:入门题) http://acm.hdu.edu.cn/showproblem.php?pid=1284 题意: 在一个国家仅有1分,2分.3分硬币,将钱N ( ...
- HDU 1284 钱币兑换问题(普通型 数量无限的母函数)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1284 钱币兑换问题 Time Limit: 2000/1000 MS (Java/Others) ...
- 题解报告:hdu 1284 钱币兑换问题(简单数学orDP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1284 Problem Description 在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很 ...
- HDU 1284 钱币兑换问题 母函数、DP
题目链接:HDU 1284 钱币兑换问题 钱币兑换问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- POJ 3181 Dollar Dayz && Uva 147 Dollars(完全背包)
首先是 Uva 147:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_p ...
- HDU 2098 分拆素数和
HDU 2098 分拆素数和 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768K (Java/Others) [题目描述 ...
随机推荐
- Sublime Text2 快捷键 (MAC版)
工具是人的延伸,可以把人变得更聪明更强大,人类正是学会了使用工具,才创造出现在的文明.作为程序员,工具开发.使用是其能力的重要体现,业内的大牛都是造工具的好手.目前身边很多人都在用sublime te ...
- 一张图解释Hadoop IPC
基于hadoop2.6.2.... 一张图Server启动,Client访问..... RPC是IPC的一种,IPC还有另外一种LPC,相关请看参考中的3 使用hadoop ipc步骤: 1.定义RP ...
- centos安装配置nginx
1.安装gcc yum install gcc 2.安装PCRE,zlib,OpenSSL(其中devel,是develop开发包的意思) yum install -y pcre pcre-devel ...
- Vector3.Lerp 插值
Vector3.Lerp 插值 static function Lerp (from : Vector3, to : Vector3, t : float) : Vector3 Description ...
- CUDA中的Toolkit
CUDA Toolkit是什么? 对于使用 C 语言和 C++ 来开发 GPU 加速应用程序的开发者来说,NVIDIA CUDA Toolkit 可提供一个综合的开发环境.CUDA Toolkit 包 ...
- Coursera台大机器学习课程笔记15 -- Three Learning Principles
这节课是最后一节,讲的是做机器学习的三个原则. 第一个是Occan's razor,即越简单越好.接着解释了什么是简单的hypothesis,什么是简单的model.关于为什么越简单越好,林老师从大致 ...
- Textview下划线注册用户跳转实现
在xml中: <TextView android:id="@+id/textView_regtext" android:layout_width="wrap_con ...
- 脚本重定向输出【错误、正确】——分析service脚本中用到的语法
<1> >&2 即 1>&2 也就是把结果输出到和标准错误一样:之前如果有定义标准错误重定向到某log文件,那么标准输出也重定向到这个log文件如:ls 2&g ...
- eclipse连接虚拟机
1.启动eclipse 2.打开 "Help/Install New Software..." 3.打开Add…… 4.输入Name: Genymobile Lo ...
- DP:Skiing(POJ 1088)
北大教你怎么滑雪 题目是中文的,要读懂题目其实不难 其实这道题挺经典的,我们这样想,他最终要找到一个最大值,这个时候我们就想到要用动态规划 那怎么用呢?我们同时这样想,由于滑雪的最高点我们不能立马找 ...