#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面值,有多少种方案? 解题思路: 赤果果的 ...
随机推荐
- GKCTF2020WP-Crypto Misc
Crypto 小学生的密码学 题目 e(x)=11x+6(mod26) 密文:welcylk (flag为base64形式) 我的解答: 考点:仿射密码,已知a,b 结果base64加密即可 flag ...
- drf实战和源码剖析----学习笔记1
学自:bilibili武沛齐老师. 武老师讲课:清晰,连贯,实用,透彻,真乃名师! # 1. 什么是前后端分离 - 不分离,主要用于后台系统(CRUD)和用户量上的情况,开发起来代价小- 分离,面向用 ...
- KNN算法实战——海伦约会(KDtree优化)
本文通过海伦约会的例子来测试之前写的KDTree的效果,并且探讨了特征是否进行归一化对整个模型的表现的影响.最后发现在机器学习中,特征归一化确实对模型能提供非常大的帮助. 1 from KDTree ...
- 现代 CPU 技术发展
介绍 这篇文章主要是介绍CPU技术的发展,包括最近几十年CPU性能提升和半导体工艺发展,当前技术发展方向.希望可以帮助软件开发者理解CPU指令集和组成运行原理.CPU性能提升的现状和瓶颈.CPU技术发 ...
- 从零玩转SpringSecurity+JWT整合前后端分离-从零玩转springsecurityjwt整合前后端分离
title: 从零玩转SpringSecurity+JWT整合前后端分离 date: 2021-05-06 14:56:57.699 updated: 2021-12-26 17:43:19.478 ...
- 【Redis】一文掌握Redis原理及常见问题
Redis是基于内存数据库,操作效率高,提供丰富的数据结构(Redis底层对数据结构还做了优化),可用作数据库,缓存,消息中间件等.如今广泛用于互联网大厂,面试必考点之一,本文从数据结构,到集群,到常 ...
- springsecurity 使用浅谈(一)
1. 背景 springsecurity框架主要用于Web应用的认证和授权.所谓认证就是验证当前访问系统的是不是本系统的用户,并且要确认具体是哪个用户.而授权就是经过认证后判断当前用户是否有权 限进行 ...
- python异步编程之asyncio低阶API
低阶API介绍 asyncio中低阶API的种类很多,涉及到开发的5个方面.包括: 获取事件循环 事件循环方法集 传输 协议 事件循环策略 本篇中只讲解asyncio常见常用的函数,很多底层函数如网络 ...
- 热闹的人工智能VS酷寒的资本寒冬,2023年AI Agent项目盘点与融资分析
2023年国内AI Agent下项目大盘点,科技大厂与创业公司齐头并进 热闹人工智能VS酷寒资本寒冬,2023年AI Agent项目盘点与融资分析 资本寒冬下的AIGC,为什么这些AI Agent项目 ...
- 文心一言 VS 讯飞星火 VS chatgpt (47)-- 算法导论6.1 5题
五.一个已排好序的数组是一个最小堆吗? 文心一言: 一个已排好序的数组不一定是一个最小堆.最小堆是一种特殊的二叉树,它满足以下性质:对于任意节点 x,其父节点 y 的值都小于等于 x 的值.而一个已排 ...