#2069:Coin Change(完全背包)
Problem Description
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
题意:给你面值有1,5,10,25,50的币种,然后随意输入一个钱的数目,问用这些面值刚好凑成这个钱的方法有多少个(最多100个硬币)
思路:完全背包
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int a[5] = { 1,5,10,25,50 };
ll dp[255][101];//dp[j][k]:用k个硬币组成j值的个数
int main()
{
int n;
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for (int i = 0; i < 5; i++) {
for (int k = 1; k <= 100; k++) {//k个硬币
for (int j = a[i]; j <= 250; j++) {
dp[j][k] += dp[j - a[i]][k - 1];
}
}
}
while (cin >> n) {
int res = 0;
for (int i = 0; i <= 100; i++) {
res += dp[n][i];
}
cout << res << endl;
}
return 0;
}
#2069:Coin Change(完全背包)的更多相关文章
- hdu 2069 Coin Change(完全背包)
Coin Change Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDOJ 2069 Coin Change(母函数)
Coin Change Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 2069 Coin Change
Coin Change Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- HDU 2069 Coin Change(完全背包变种)
题意:给你5种银币,50 25 10 5 1,问你可以拼成x的所有可能情况个数,注意总个数不超过100个 组合数问题,一看就是完全背包问题,关键就是总数不超过100个.所有我们开二维dp[k][j], ...
- 题解报告:hdu 2069 Coin Change(暴力orDP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2069 Problem Description Suppose there are 5 types of ...
- uva674 Coin Change ——完全背包
link:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- Light oj 1233 - Coin Change (III) (背包优化)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1233 题目就不说明了. 背包的二进制优化,比如10可以表示为1 2 4 3,而 ...
- hdu2069(Coin Change)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2069 Coin Change Time Limit: 1000/1000 MS (Java/Other ...
- UVA.674 Coin Change (DP 完全背包)
UVA.674 Coin Change (DP) 题意分析 有5种硬币, 面值分别为1.5.10.25.50,现在给出金额,问可以用多少种方式组成该面值. 每种硬币的数量是无限的.典型完全背包. 状态 ...
- Lightoj 1231 - Coin Change (I) (裸裸的多重背包)
题目链接: Lightoj 1231 - Coin Change (I) 题目描述: 就是有n种硬币,每种硬币有两个属性(价值,数目).问用给定的硬币组成K面值,有多少种方案? 解题思路: 赤果果的 ...
随机推荐
- PX4安装环境测试
1.ROS环境测试 安装ROS版本:melodic roscore // 注意下面是打开一个新的终端,roscore一直在运行 rosrun turtlesim turtlesim_node // 再 ...
- ABAP 泰国凭证批导 报错 F51 192 输入一个业务场景
泰国凭证批导报错 F51 192 输入一个业务场景 方案一: 方案二: ID_BUPLA 用户参数
- 0x06.HelloPHP
PHP基础 格式 最后一句可以不加分号 <?php echo "hello" ?> 可以不加结束标签,但是最后一句要加分号 <?php echo "he ...
- .NET Conf 2023 Chengdu - 成都站圆满结束!
今年的.NET Conf 2023,中国区首次有两个会场举办Local Event,成都会场已于上周六12月9日圆满结束. 本次成都会场共计100+余名.NET开发者报名参与,共计10+名志愿者参与筹 ...
- 是谁的简历上全是秒杀商城和RPC啊?
是不是还在苦于自己简历上的项目离不开商城.RPC.秒杀.论坛.外卖.点评等等烂大街的项目?是不是翻遍全网再很难找到一个既有含金量又能看得懂的项目?那么现在就不用找了,下面这个项目一定适合你! 高性能短 ...
- 基于Raft算法的DLedger-Library分析
1 背景 在分布式系统应用中,高可用.一致性是经常面临的问题,针对不同的应用场景,我们会选择不同的架构方式,比如master-slave.基于ZooKeeper选主.随着时间的推移,出现了基于Raft ...
- 封装RabbitTemplate,使用自定义消息转换器
前面创建项目我就省了...活不多说直接上代码! 核心代码 RabbitMQConfig import lombok.extern.slf4j.Slf4j; import org.springframe ...
- 【Python】【OpenCV】Cameo项目(一)实时显示摄像头帧
Cameo项目介绍: 1.实时捕获并显示摄像头帧. 2.具备截图.保存视频和退出三个功能键. 要求存在文件:manager.py 和 cameo.py 一.manager.py 两个类:Capture ...
- ElasticSearch之查看集群的参数
参考Cluster get settings API. 命令样例,不指定参数,如下: curl -X GET "https://localhost:9200/_cluster/setting ...
- 通过 KernelUtil 截取 QQ / TIM 客户端 ClientKey 详细教程
前言 众所周知,由于最新版本 QQ 9.7.20 已经不能通过模拟网页快捷登录来截取 Clientkey,估计是针对访问的程序做了限制,然而经过多方面测试,诸多的地区.环境.机器也针对这种获取方法做了 ...