博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
uva 147 - Dollars(动态规划--完全背包)
阅读量:4034 次
发布时间:2019-05-24

本文共 1919 字,大约阅读时间需要 6 分钟。

1、

2、题目大意:

给定11种面值分别为$100, $50, $20, $10, and $5 notes and $2, $1, 50c, 20c, 10c and 5c coins的钱,现在给定一个钱数,求出可以组成的种类数,类似于uva 674,不过此题的精度太强了,纠结。。。

int n=(int)(nn*100+0.5);,注意用long long ,种类数可能非常大

用dp[i][j]表示用前i种硬币,组成j分的种类数,

状态转移方程:dp[i][j]+=DP(i-1,j-k*d[i]);

 

3、题目:

 

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 tex2html_wrap_inline25 20c, 2 tex2html_wrap_inline25 10c, 10c+2 tex2html_wrap_inline25 5c, and 4 tex2html_wrap_inline25 5c.

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

0.202.000.00

0.20                4  2.00              293

 

4、AC代码:

#include
#define N 30005#include
#define ll long longint d[11]= {5,10,20,50,100,200,500,1000,2000,5000,10000};ll dp[15][N];//dp[i][j]表示用前i种硬币,组成j分的种类数ll DP(ll i,ll j){ //printf("%d %d %d\n",i,j,dp[i][j]); if(dp[i][j]!=-1) return dp[i][j]; dp[i][j]=0; for(int k=0;j-k*d[i]>=0;k++) { dp[i][j]+=DP(i-1,j-k*d[i]); } return dp[i][j];}int main(){ double nn; memset(dp,-1,sizeof(dp));//赋值一次即可,否则可能会超时 while(scanf("%lf",&nn)!=EOF) { if(nn==0.00) break; int n=(int)(nn*100+0.5);//注意精度 for(ll i=0; i<=n; i++) dp[0][i]=1; printf("%6.2f%17lld\n",nn,DP(10,n)); } return 0;}/*0.202.000.00 0.20 4 2.00 293*/

 

 

 

转载地址:http://vqddi.baihongyu.com/

你可能感兴趣的文章
IP报文格式学习笔记
查看>>
autohotkey快捷键显示隐藏文件和文件扩展名
查看>>
Linux中的进程
查看>>
学习python(1)——环境与常识
查看>>
学习设计模式(3)——单例模式和类的成员函数中的静态变量的作用域
查看>>
自然计算时间复杂度杂谈
查看>>
当前主要目标和工作
查看>>
Intellij IDEA启动优化,让开发的感觉飞起来
查看>>
使用 Springboot 对 Kettle 进行调度开发
查看>>
如何优雅的编程,lombok你怎么这么好用
查看>>
一文看清HBase的使用场景
查看>>
除了负载均衡,Nginx还可以做很多,限流、缓存、黑白名单
查看>>
解析zookeeper的工作流程
查看>>
搞定Java面试中的数据结构问题
查看>>
慢慢欣赏linux make uImage流程
查看>>
linux内核学习(7)脱胎换骨解压缩的内核
查看>>
以太网基础知识
查看>>
慢慢欣赏linux 内核模块引用
查看>>
kprobe学习
查看>>
慢慢欣赏linux phy驱动初始化2
查看>>