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, or two 5-cent coins and one 1-cent coin, or 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 100 coins.
Input
The input file contains any number of lines, each one consisting of a number ( ≤250 ) 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
题意:有五种面值的硬币,支付已知价格时有几种方案。
思路:暴力枚举(动态规划也挺好的,不过我不会写。。。)
#include <stdio.h>
int main()
{ int n; while(scanf("%d",&n)!=EOF) { int ans=0; //abcde分别表示面值为50、25、10、5、1的硬币的个数for(int a=0;a<=5;a++) //abcd的范围是通过“each one consisting of a number ( ≤250 ) for the amount of money in cents.”这句话来确定的,需要支付的价格不会超过250for(int b=0;b<=10-2*a;b++)for(int c=0;c<=25-5*a;c++)for(int d=0;d<=50-2*c;d++)for(int e=0;e<=100;e++) //e的范围是通过“Your program should be able to handle up to 100 coins. ”来确定的if(50*a+25*b+10*c+5*d+e==n&&a+b+c+d+e<=100) //如果当前总价格与输入的价格相同且硬币总个数小于等于100,则满足题意,方案数加一ans++;printf("%d\n",ans); } return 0;
}
Coin Change相关推荐
- Lightoj 1231 - Coin Change (I) (裸裸的多重背包)
题目链接: Lightoj 1231 - Coin Change (I) 题目描述: 就是有n种硬币,每种硬币有两个属性(价值,数目).问用给定的硬币组成K面值,有多少种方案? 解题思路: 赤果果的 ...
- C++coin change 硬币找零(附完整源码)
coin change 硬币找零 coin change 硬币找零算法的完整源码(定义,实现,main函数测试) coin change 硬币找零算法的完整源码(定义,实现,main函数测试) #in ...
- 利用动态规划(DP)解决 Coin Change 问题
问题来源 这是Hackerrank上的一个比较有意思的问题,详见下面的链接: https://www.hackerrank.com/challenges/ctci-coin-change 问题简述 给 ...
- hdu2069(Coin Change)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2069 Coin Change Time Limit: 1000/1000 MS (Java/Other ...
- LeetCode 518 Coin Change 2 (python)
目录 LeetCode 518 Coin Change 2 (python) Code 欢迎一起来参与leetcode刷题项目 LeetCode 518 Coin Change 2 (python) ...
- Coin Change【硬币找零】
一.题目 英文:Coin Change 中文:硬币找零 二.内容要求 英文:You are given coins of different denominations and a total amo ...
- LeetCode Coin Change(动态规划)
问题:给定不同面额的硬币coins和一个总金额amount,求凑成总金额所需的最少硬币个数 思路:第一种方法使用递归法,枚举x使用第coinIndex个硬币的amount/coins[coinInde ...
- leetcode 322. Coin Change | 322. 零钱兑换(动态规划)
题目 https://leetcode.com/problems/coin-change/ 题解 也许是第一次在没看答案的情况下写的动态规划- 第一反应是,这题不是广义背包吗?想了一下,不是,因为广义 ...
- LeetCode 322. Coin Change
原题 You are given coins of different denominations and a total amount of money amount. Write a functi ...
最新文章
- json.dumps()和json.loads()
- Java:银行账户类
- python内核大小_关于keras.layers.Conv1D的kernel_size参数使用介绍
- android 先拍照后对焦,先拍照后对焦 荣耀6或搭全焦拍摄功能
- VS2003,VS2005,VS2008 低版本打开高版本的解决方案和工程文件
- LeetCode 61. 旋转链表(python、c++)
- 趣学 C 语言(二)—— typedef 与 #define
- 线段树扫描线(1---算矩形的总面积)
- python英文文本词性分析
- python代码范文_如何给你的Python代码“减负”,这里有一份指南请查收
- N-Tiers开发方式(COM+组件的注册、修改)
- MBSE系统工程是什么
- 天问: 量子力学中的波函数到底表示什么?
- PHP定时任务 - PHP自动定时循环执行任务实例代码
- windows删除不了文件解决方法(亲测有效)
- 【mba项目管理论文】S 公司项目管理绩效评价现状与问题(节选)
- CF338(div2)
- Cadence Allegro如何设置stroke快捷命令
- XML 解析生成工具
- Microsoft Corporation 去掉 windows 修改 启动加载 版权