动态规划-uva-674

uva-674- Coin Change

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种面值的硬币,1、5、10、25、50分。给定找零总额,问有多少种组合方法。

分析:动态规划。int不会溢出。

注意:HDOJ-2069 与此题类似。但有要求,硬币总数不能超过100个。似乎要用母函数。高端,不会。。。

动态规划-uva-674

时间: 2024-08-27 03:22:35

动态规划-uva-674的相关文章

UVa 674 & hdu 2069 Coin Change (母函数,dp)

链接:uva 674 题意:有5中货币,价值分别为 50-cent, 25-cent, 10-cent, 5-cent,1-cent,数量都为无限个, 给定一个数 n,求用上述货币组成价值为 n 的方法有多少? 分析:因为n<=7489,可以用 母函数 或 dp 打表 对于dp状态方程为: dp[j]+=dp[j-c[i]] 母函数: #include<stdio.h> int c1[7500],c2[7500],w[5]={1,5,10,25,50};; void mhs() { in

uva 674 (入门DP, 14.07.09)

 Coin Change  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 an

uva 674 Coin Change 经典dp入门

Coin Change Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Practice UVA 674 Appoint description: Description Download as PDF Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to m

【暑假】[深入动态规划]UVa 12170 Easy Climb

UVa 12170 Easy Climb 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=24844 思路:  引别人一个题解琢磨一下: from:http://blog.csdn.net/glqac/article/details/45257659 代码: 1 #include<iostream> 2 #include<algorithm> 4 #define FOR(a,b,c) for(int a

【暑假】[深入动态规划]UVa 10618 Fixing the Great Wall

UVa 10618 Fixing the Great Wall 题目:  http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=36139 思路:   数轴上有n个点需要修复,每个点有信息c,x,d 表示位于x且在t时修缮的费用是c+d*t,找一个修缮序列使n个点能全部修缮且有费用最小. 可以发现:在任意时刻,修缮完的点都是连续的,因为修缮不需要时间,将一些点“顺手”修缮了肯定不差. d[i][j][k],表示已经将i-j个点修缮

【暑假】[深入动态规划]UVa 1628 Pizza Delivery

UVa 1628 Pizza Delivery 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=51189 思路:   本体与修缮长城一题有所相似.所以解法有相似之处. 不同之处就是本体可能会产生负情况,即送餐时间晚了客户会反过来找你要钱所以需要放弃,但修缮长城只有费用,顺手修了肯定是一个不错的选择. 依旧将区间两端与位置作为状态不过要添加一维cnt表示还需要送餐的人数.类似地定义:d[i][j][cnt][p]表示

【暑假】[深入动态规划]UVa 1627 Team them up!

UVa 1627 Team them up! 题目: Team them up! Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description Your task is to divide a number of persons into two teams, in such a way, that: everyone belongs to one of th

【暑假】[深入动态规划]UVa 10618 The Bookcase

UVa 12099  The Bookcase 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=42067 思路:   将n本书分配到三层,使得形成的书架w*h最小 提前将书籍按照高度排序,因为无论第一本书(最高的书)无论放在那一层都会被考虑到,所以规定将它放在第一层,且第二层比第三层高. 因为从大到小排序的关系,只要jk==0那么新加入的书i就是该层的高度,否则高度不变. 设d[i][j][k]表示考虑过i本书第二

【暑假】[深入动态规划]UVa 1412 Fund Management

UVa 1412 Fund Management 题目: UVA - 1412 Fund Management Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description Frank is a portfolio manager of a closed-end fund for Advanced Commercial Markets (ACM ). Fund

【暑假】[深入动态规划]UVa 10618 Tango Tango Insurrection

UVa 10618 Tango Tango Insurrection 题目: Problem A: Tango Tango Insurrection You are attempting to learn to play a simple arcade dancing game. The game has 4 arrows set into a pad: Up, Left, Down, Right. While a song plays, you watch arrows rise on a s