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

4
13

5种面值钱币,要求出兑换某个钱的方法总数:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<limits.h>
typedef long long LL;
using namespace std;
int v[5]={1,5,10,25,50};
int dp[100000];
int main()
{
int n;
while(~scanf("%d",&n))
{
memset(dp,0,sizeof(dp));
dp[0]=1;
for(int i=0;i<5;i++)
{
for(int j=v[i];j<=n;j++)
dp[j]+=dp[j-v[i]]; }
printf("%d\n",dp[n]);
}
return 0;
}

UVA 674 Coin Change (DP)的更多相关文章

  1. UVA 674 Coin Change(dp)

    UVA 674  Coin Change  解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730#problem/ ...

  2. UVA 674 Coin Change (完全背包)

    解法 dp表示目前的种数,要全部装满所以f[0]=1其余为0的初始化是必不可少的 代码 #include <bits/stdc++.h> using namespace std; int ...

  3. UVa 674 Coin Change(完全背包)

    https://vjudge.net/problem/UVA-674 题意: 计算兑换零钱的方法共有几种. 思路: 完全背包基础题. #include<iostream> #include ...

  4. UVA.674 Coin Change (DP 完全背包)

    UVA.674 Coin Change (DP) 题意分析 有5种硬币, 面值分别为1.5.10.25.50,现在给出金额,问可以用多少种方式组成该面值. 每种硬币的数量是无限的.典型完全背包. 状态 ...

  5. UVA 674 Coin Change 换硬币 经典dp入门题

    题意:有1,5,10,25,50五种硬币,给出一个数字,问又几种凑钱的方式能凑出这个数. 经典的dp题...可以递推也可以记忆化搜索... 我个人比较喜欢记忆化搜索,递推不是很熟练. 记忆化搜索:很白 ...

  6. UVa 674 Coin Change【记忆化搜索】

    题意:给出1,5,10,25,50五种硬币,再给出n,问有多少种不同的方案能够凑齐n 自己写的时候写出来方案数老是更少(用的一维的) 后来搜题解发现,要用二维的来写 http://blog.csdn. ...

  7. uva 674 Coin Change 换钱币【完全背包】

    题目链接:https://vjudge.net/contest/59424#problem/A 题目大意: 有5种硬币, 面值分别为1.5.10.25.50,现在给出金额,问可以用多少种方式组成该面值 ...

  8. UVA 674 Coin Change 硬币转换(完全背包,常规)

    题意:有5种硬币,个数无限的,组成n元的不同方案有多少种? 思路:常规完全背包.重点在dp[0]=1,dp[j]中记录的是组成 j 元的方案数.状态转移方程dp[j+coin[i]]+=dp[j]. ...

  9. uva 116 Unidirectional TSP (DP)

    uva 116 Unidirectional TSP Background Problems that require minimum paths through some domain appear ...

随机推荐

  1. JAVA 锁

    JAVA 锁 锁的概念 Java中的锁是控制资源访问的一种方式.它弥补了synchronized的可操作性不强的不足. Java的锁都实现了Lock接口.Lock结构定义了锁的基本操作. 函数 解释 ...

  2. Linux基本命令 目录

    Linux基本命令 目录 Linux基本命令(1)管理文件和目录的命令 Linux基本命令(2)有关磁盘控件的命令 Linux基本命令(3)文件备份和压缩的命令 Linux基本命令(4)有关关机和查看 ...

  3. dzzoffice注册开启

    dzzoffice默认安装注册选线是关闭的,需要在“系统设置”里打开. 设置方法 开始菜单=>系统设置=>注册与访问=> 将允许用户注册选勾,选上. 然后提交保存.

  4. 游戏BI,起步了。

    思索许久,终于决定自己的发展将会是游戏的BI. 即说即做,本文是我未来BI工作的开端. 传统的游戏BI,只是将运营的工作数据化,流量的变现指标化.和网站类似,无外乎用户导入,流失,保有,付费,回访等等 ...

  5. 僵尸进程&孤儿进程

    http://www.cnblogs.com/Anker/p/3271773.html

  6. dom cookie记录用户名

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  7. hdu5072-Coprime(容斥原理)

    题意:给N个互不相同的数,选择出两两互质或者两两不互质的三个数,有多少种选法. 题解:一共有C(N,3)中选择方式,减去不符合要求的,剩下的就是答案. 详见 http://blog.csdn.net/ ...

  8. Python内置方法的时间复杂度(转)

    原文:http://www.orangecube.net/python-time-complexity 本文翻译自Python Wiki本文基于GPL v2协议,转载请保留此协议. 本页面涵盖了Pyt ...

  9. 杭电1010Tempter of the Bone

    Tempter of the Bone Problem Description The doggie found a bone in an ancient maze, which fascinated ...

  10. 网易及新浪IP查询接口

    通过IP地址获取对应的地区信息通常有两种方法:1)自己写程序,解析IP对应的地区信息,需要数据库.2)根据第三方提供的API查询获取地区信息. 第一种方法,参见文本<通过纯真IP数据库获取IP地 ...