#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面值,有多少种方案? 解题思路: 赤果果的 ...
随机推荐
- 数据库系列:RR和RC下,快照读的区别
数据库系列:MySQL慢查询分析和性能优化 数据库系列:MySQL索引优化总结(综合版) 数据库系列:高并发下的数据字段变更 数据库系列:覆盖索引和规避回表 数据库系列:数据库高可用及无损扩容 数据库 ...
- iOS程序入口结构
盛年不重来,一日难再晨.及时宜自勉,岁月不待人. 1. 程序入口 在我们开始开发app的时候,第一步往往是通过设置AppDelegate.m的代理方法开始写一些启动的东西,然后再通过控制器View ...
- [FJOI2017]矩阵填数 (容斥原理)
题目传送门 现在看来熊猫杯的J题原来是个容斥套路题,按照值域排序后根据值域划分方块数,枚举子集容斥计算即可. #include<cstdio> #include<algorithm& ...
- mysql之慢sql配置与分析
mysql的慢查询sql是通过日志记录慢SQL--(俗称慢查询日志)默认的情况下,MySQL数据库不开启慢查询日志(slow query log),需要手动把它打开 开启慢查询日志 SET GLOBA ...
- k8s安装网络插件calico出现error validating "calico.yaml": error validating data: invalid object to validate; if you choose to ignore these errors, turn validation off with --validate=false
解决办法:使用下面版本的calico curl https://docs.projectcalico.org/v3.20/manifests/calico.yaml -O
- SpringBoot核心注解:@SpringBootApplication
@SpringBootApplication它是由三个注解的复合: @ComponentScan @SpringConguration @EnableAutoConfiguration 三个注解的作用 ...
- 【Python】【OpenCV】视频帧和摄像头帧操作 and 窗口显示
一.读取写入视频文件 1 import cv2 2 3 # 创建一个视屏捕获对象 4 videoCapture = cv2.VideoCapture('AVI.avi') 5 6 # 获取视频的属性值 ...
- Python——Html(语法、格式、段落、文字处理、路径、超链接、图片、视频)
HTML(Hyper Text Markup Language超文本标记语言)用特殊的一种标签把需要特殊展示出来的内容圈起来.这就是标记语言语法规则 <标记>被标记的内容</标记&g ...
- Android学习--Intent
Intent : Intent 是一个动作的完整描述,一种运行时的绑定机制,Intent中包含对Intent有兴趣的组件信息,如对动作的产生组件.接受组件和传递的数据信息.Android根据此Inte ...
- vue3 + element-plus 的 upload + axios + django 文件上传并保存
之前在网上搜了好多教程,一直没有找到合适自己的,要么只有前端部分没有后端,要么就是写的不是很明白.所以还得靠自己摸索出来后,来此记录一下整个过程. 其实就是不要用默认的 action,要手动实现上传方 ...