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 ...
随机推荐
- no protocol specified
基于vncserver安装oracle or oracle RAC时 以root账号运行xhost + 在切换到grid or oracle安装oracle database file or clus ...
- 张王李相亲应用if else
package hello; public class to { public static void main(String[]args){ int a =1,b=0; int c =1,d=0; ...
- swig include使用方法
{% block content2 %} {% include "footer.html" %} {% endblock %} include语句必须放到 block模块中,不然不 ...
- Database(Mysql)发版控制二
author:skate time:2014/08/18 Database(Mysql)发版控制 The Liquibase Tool related Database 一.Installation ...
- 基于 dbms_redefinition 在线重定义表
Oracle 支持在线重定义表,也就是说我们可以在修改表结构(DDL)的同时进行相关的DQL.DML操作,使得前端的DML根本感觉不到表结构实际上已经发生了变化,对于用户而言是完全透明的.当然在线重定 ...
- POJ 1037 DP
题目链接: http://poj.org/problem?id=1037 分析: 很有分量的一道DP题!!! (参考于:http://blog.csdn.net/sj13051180/article/ ...
- C++ typedef
C++ typedef 作用:用来定义类型的同义词,用作类型的说明符. 用法:typedef typeName myTypeName; 使用目的:1. 为了隐藏特定类型的实现,强调使用类型的目的.2. ...
- java代理课程测试 spring AOP代理简单测试
jjava加强课程测试代码 反射. 代理 .泛型.beanUtils等 项目源码下载:http://download.csdn.net/detail/liangrui1988/6568169 热身运动 ...
- thinkphp phpexcel导入
上次做了一个基于tp3.2.3的phpexcel导出,这次是phpexcel导入,准备材料phpexcel(不知道下载地址的查看我上一篇博文),虽说是基于thinkphp3.2.3来的,也只不过是引入 ...
- iter, yield与enumerate的实现
模拟实现一个enumerate函数 def myEnumerate(seq, start=0): results = [] n = start for i in seq: results.append ...