UVA 674 Coin Change(dp)
UVA 674 Coin Change 解题报告
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730#problem/E
题目:
Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make changes with these coins for a given amount of money.
For example, if we have 11 cents, then we can make changes with one 10-cent coin and one 1-cent coin, two 5-cent coins and one 1-cent coin, one 5-cent coin and six 1-cent coins, or eleven 1-cent coins. So there are four ways of making changes for 11 cents with the above coins. Note that we count that there is one way of making change for zero cent.
Write a program to find the total number of different ways of making changes for any amount of money in cents. Your program should be able to handle up to 7489 cents.
Input
The input file contains any number of lines, each one consisting of a number for the amount of money in cents.
Output
For each input line, output a line containing the number of different ways of making changes with the above 5 types of coins.
Sample Input
11
26
Sample Output
11
26
题目大意:
有5种硬币,分别是1,5,10,25,50。现有一定金额的钱由这5种硬币组成,求共有多少种组成方式。
分析:
完全背包,因为硬币数量不限。注意1+10和10+1是一样的,用递推的方式解,要将硬币从小到大排序。
要注意估算时间复杂度。
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std; const int maxn=; int dp[maxn];//钱数为n时的最多组成方式
int coin[]={,,,,};//5种类型的硬币 int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
memset(dp,,sizeof(dp));
dp[]=;
for(int i=;i<;i++)
for(int j=;j<=n;j++)
dp[j+coin[i]]+=dp[j];//注意dp的转移顺序
printf("%d\n",dp[n]);
}
return ;
}
UVA 674 Coin Change(dp)的更多相关文章
- UVA 674 Coin Change (DP)
Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make c ...
- UVA 674 Coin Change (完全背包)
解法 dp表示目前的种数,要全部装满所以f[0]=1其余为0的初始化是必不可少的 代码 #include <bits/stdc++.h> using namespace std; int ...
- UVa 674 Coin Change(完全背包)
https://vjudge.net/problem/UVA-674 题意: 计算兑换零钱的方法共有几种. 思路: 完全背包基础题. #include<iostream> #include ...
- UVA.674 Coin Change (DP 完全背包)
UVA.674 Coin Change (DP) 题意分析 有5种硬币, 面值分别为1.5.10.25.50,现在给出金额,问可以用多少种方式组成该面值. 每种硬币的数量是无限的.典型完全背包. 状态 ...
- UVA 674 Coin Change 换硬币 经典dp入门题
题意:有1,5,10,25,50五种硬币,给出一个数字,问又几种凑钱的方式能凑出这个数. 经典的dp题...可以递推也可以记忆化搜索... 我个人比较喜欢记忆化搜索,递推不是很熟练. 记忆化搜索:很白 ...
- UVa 674 Coin Change【记忆化搜索】
题意:给出1,5,10,25,50五种硬币,再给出n,问有多少种不同的方案能够凑齐n 自己写的时候写出来方案数老是更少(用的一维的) 后来搜题解发现,要用二维的来写 http://blog.csdn. ...
- uva 674 Coin Change 换钱币【完全背包】
题目链接:https://vjudge.net/contest/59424#problem/A 题目大意: 有5种硬币, 面值分别为1.5.10.25.50,现在给出金额,问可以用多少种方式组成该面值 ...
- UVA 674 Coin Change 硬币转换(完全背包,常规)
题意:有5种硬币,个数无限的,组成n元的不同方案有多少种? 思路:常规完全背包.重点在dp[0]=1,dp[j]中记录的是组成 j 元的方案数.状态转移方程dp[j+coin[i]]+=dp[j]. ...
- uva 116 Unidirectional TSP (DP)
uva 116 Unidirectional TSP Background Problems that require minimum paths through some domain appear ...
随机推荐
- GridView分页功能的实现
当GridView中显示的记录很多的时候,可以通过GridView的分页功能来分页显示这些记录.如果GridView是直接绑定数据库,则很简单:将"启动分页"打勾即可. 如果是用代 ...
- DDR、DDR2、DDR3产品区别
DDR采用一个周期来回传递一次数据,因此传输在同时间加倍,因此就像工作在两倍的工作频率一样.为了直观,以等效的方式命名,因此命名为DDR 200 266 333 400. DDR2尽管工作频率没有变化 ...
- Developing your first FNC custom control
Friday, May 13, 2016 Some weeks ago, we released the TMS FNC UI Pack, a set of Framework Neutral Com ...
- Windows Azure 社区新闻综述(#73 版)
欢迎查看最新版本的每周综述,其中包含有关云计算和 Windows Azure的社区推动新闻.内容和对话. 以下是过去一周基于您的反馈汇集在一起的内容: 文章.视频和博客文章 · Windows A ...
- hdu 2563 统计问题
统计问题 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submissi ...
- Euromonitor 2013年奢侈品报告精选 |华丽志
Euromonitor 2013年奢侈品报告精选 |华丽志 Euromonitor 2013年奢侈品报告精选
- (92) Is there a better crawler than Scrapy? - Quora
(92) Is there a better crawler than Scrapy? - Quora Is there a better crawler than Scrapy?Edit
- Hive索引
1. Hive索引概述 Hive的索引目的是提高Hive表指定列的查询速度. 没有索引时.类似'WHERE tab1.col1 = 10' 的查询.Hive会载入整张表或分区.然后处理全 ...
- redis 缓存技术与memcache的最大差别
1 什么是redis redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对很多其它,包含string(字符串).list(链表).set(集合)和zs ...
- myeclipse 配置weblogic 异常
java.lang.UnsupportedClassVersionError: Bad version number in .class file当前JDK与weblogic版本不匹配.