#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面值,有多少种方案? 解题思路: 赤果果的 ...
随机推荐
- 微信小程序直播接入指南
微信小程序直播接入指南 小程序直播组件接入指引 一.简介 小程序直播,是微信提供给小程序开发者的直播组件.通过调用该组件,商家可以在小程序中实现直播功能. 按下面的使用说明接入,在你的小程序中引入直播 ...
- 第五周阅读笔记|人月神话————胸有成竹(Calling the Shot)
这个章节标题是胸有成竹,而要做到胸有成竹就必须在项目计划阶段我们对项目的预测和估算都需要很准确.因此整个章节的内容就是在讲估算,而估算就涉及到预测和估算模型,估算要做到准确必须通过前期多个历史项目和版 ...
- 什么是物理信息系统(cps)?
物理信息系统(Cyber-Physical Systems,简称CPS)是由计算机.网络和物理组件相互交互的智能系统.它集成了实时计算.通信网络和物理过程控制,以提供智能化的感知.决策和执行功能. C ...
- flask的cookie和session会话保持
Cookie 获取请求cookie 通过请求对象中的cookies属性可以获取cookie. 实例: from flask import Flask, request @app.route(" ...
- python操作mongodb副本集(mongodb高可用)
https://pymongo.readthedocs.io/en/stable/examples/high_availability.html# pymongo比较"智能",只要 ...
- navicat连接服务器mysql
navicat连接服务器mysql 第一步:配置防火墙 连接服务器的mysql数据库,我们首先需要在服务器上放行3306端口(MySQL服务对应的端口),进入服务器管理页面防火墙,点击添加规则,放行3 ...
- ifconfig详解
linux下ifconfig命令详解 ifconfig 是一个用来查看.配置.启用或禁用网络接口的工具,这个工具极为常用的.可以用这个工具来临时性的配置网卡的IP地址.掩码.广播地址.网关等.也可以把 ...
- CUDA驱动深度学习发展 - 技术全解与实战
全面介绍CUDA与pytorch cuda实战 关注TechLead,分享AI全维度知识.作者拥有10+年互联网服务架构.AI产品研发经验.团队管理经验,同济本复旦硕,复旦机器人智能实验室成员,阿里云 ...
- Blazor入门100天 : 身份验证和授权之 OpenID 与 OAuth2
目录: OpenID 与 OAuth2 基础知识 Blazor wasm Gitee 码云登录 Blazor wasm GitHub 登录 Blazor wasm Google 登录 Blazor w ...
- String 类和 STL (Standard Template Library)
目录 一. string 类 1. 构造字符串 2. string类输入 3. 使用字符串 4. 其他string类方法 5. 字符串种类 一. string 类 很多应用程序都需要处理字符串.C语言 ...