#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面值,有多少种方案? 解题思路: 赤果果的 ...
随机推荐
- 飞码LowCode前端技术之画布的设计
简介 本章节从精准定位.分层设计.异步组件.拖拽四个方面分析飞码画布设计. 一.精准定位设计 飞码画布是一个套件,可对外提供画布能力.精准定位有两种情况,一是目标组件无子组件,而是目标组件有子组件. ...
- 洛谷5789 [TJOI2017]可乐(矩阵快速幂,Floyd思想)
题意:可乐机器人有三种行为: 停在原地,去下一个相邻的城市,自爆.它每一秒都会随机触发一种行为.现在给加里敦星球城市图,在第 0秒时可乐机器人在 1号城市,问经过了 t秒,可乐机器人的行为方案数是多少 ...
- mysql数据库数据同步几种通用方法?
MySQL数据库数据同步的几种通用方法包括以下几个方面: 一.基于主从同步 主从同步是 MySQL 数据库最为常见和基本的同步方式,即其中一台 MySQL 服务器作为主服务器(Master),另外一台 ...
- [ARC122E] Increasing LCMs
Problem Statement We have a sequence of $N$ positive integers: $A_1,A_2,\cdots,A_N$. You are to rear ...
- [NOI online2022普及C]字符串
题目描述 Kri 非常喜欢字符串,所以他准备找 \(t\) 组字符串研究. 第 \(i\) 次研究中,Kri 准备了两个字符串 \(S\) 和\(R\) ,其中 \(S\) 长度为 \(n\),且只由 ...
- [AGC59C] Guessing Permutation for as Long as Possible
Problem Statement A teacher has a hidden permutation $P=(P_1,P_2,\ldots,P_N)$ of $(1,2,\cdots,N)$. Y ...
- C++ Qt开发:CheckBox多选框组件
Qt 是一个跨平台C++图形界面开发库,利用Qt可以快速开发跨平台窗体应用程序,在Qt中我们可以通过拖拽的方式将不同组件放到指定的位置,实现图形化开发极大的方便了开发效率,本章将重点介绍CheckBo ...
- 5个免费、跨平台的SQLite数据库可视化工具
前言 SQLite是一个轻量级的嵌入式关系型数据库,目前最新的版本是 SQLite3.今天推荐5个实用的SQLite数据库可视化工具(GUI),帮助大家更好的管理SQLite数据库. 什么是SQLit ...
- 2023计算机保研经验贴 直博向(南大cs,计算所,科大高研院,浙大cs,交大cs,国科cs,北大cs,清华cs)
写在前面 本人作为普通选手,只能将个人经验分享一二,不能代表其他人的想法和意见,望路过的大佬们高抬贵手-,如果有相关老师或者同学认为我违反了保密条例请与我私信联系,我会第一时间删除相关内容. 个人情况 ...
- CentOS7部署后优化配置
1.安装必要的组件.升级 yum -y install wget vim cd /etc/yum.repos.d/ rm -rf /etc/yum.repos.d/*.repo wget http:/ ...