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, two 5-cent coins and one 1-cent coin, 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 7489 cents.

Input

The input file contains any number of lines, each one consisting of a number 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

这个题目的状态转移方程为dp [ j ] =sum(dp [ j - w [ i ] ] ,dp[ j ])  ;,属于多重背包问题

#include<iostream>
using namespace std;
typedef long long ll;
const int N =+;
ll dp[N];
int w[]={,,,,,};//相当与有5个物品,可以无限制的取出,每个物品的价值为w[i],,
void inin(){
dp[]=;
for(int i=;i<=;i++){
for(int j=w[i];j<=N;j++)
dp[j]+=dp[j-w[i]];
}
}
int main(){
inin();
int n;
while(cin>>n)
cout<<dp[n]<<endl;
return ;
}

洛谷网校有个题目和这个特别类似

连接在这里:https://www.luogu.org/record/21912220(这个是01背包的)状态转移方程也为(dp [ j ] =sum(dp [ j - w [ i ] ] ,dp[ j ]))

题目背景

uim神犇拿到了uoira(镭牌)后,立刻拉着基友小A到了一家……餐馆,很低端的那种。

uim指着墙上的价目表(太低级了没有菜单),说:“随便点”。

题目描述

不过uim由于买了一些辅(e)辅(ro)书,口袋里只剩MM元(M \le 10000)(M≤10000)。

餐馆虽低端,但是菜品种类不少,有NN种(N \le 100)(N≤100),第ii种卖a_iai​元(a_i \le 1000)(ai​≤1000)。由于是很低端的餐馆,所以每种菜只有一份。

小A奉行“不把钱吃光不罢休”,所以他点单一定刚好吧uim身上所有钱花完。他想知道有多少种点菜方法。

由于小A肚子太饿,所以最多只能等待11秒。

输入格式

第一行是两个数字,表示NN和MM。

第二行起NN个正数a_iai​(可以有相同的数字,每个数字均在10001000以内)。

输出格式

一个正整数,表示点菜方案数,保证答案的范围在intint之内。

输入输出样例

输入 #1复制

4 4
1 1 2 2
输出 #1复制

3
#include<iostream>
#include<cstdio>
using namespace std;
const int N=1e5+;
int dp[N];
int w[N];
int main()
{
int n,m;
cin>>n>>m;
for(int i=;i<=n;i++){
cin>>w[i];
} dp[]=;
for(int i=;i<=n;i++){
for(int j=m;j>=w[i];j--)
dp[j]+=dp[j-w[i]];
} cout<<dp[m]<<endl;
return ;
}

对着这一类的问题的总结:这一类问题是背包问题里的解决方案的个数状态方程为dp[ j  ] = sum(dp[ j ]  , dp[j-w[ i ] ])

就是在背包容量为m下的解决方案的个数 直接累加就可以了。

https://www.cnblogs.com/Accepting/p/11278384.html 这个是背包问题中  最小值问题

Coin Change UVA的更多相关文章

  1. E - Coin Change UVA - 674 &&(一些记录路径的方法)

    这一道题并不难,我们只需要将dp数组先清空,再给dp[0]=1,之后就按照完全背包的模板写 主要是我们要证明着一种方法不会出现把(1+3+4)(1+4+3)当作两种方法,这一点如果自己写过背包的那个表 ...

  2. UVA 674 Coin Change(dp)

    UVA 674  Coin Change  解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730#problem/ ...

  3. UVA.674 Coin Change (DP 完全背包)

    UVA.674 Coin Change (DP) 题意分析 有5种硬币, 面值分别为1.5.10.25.50,现在给出金额,问可以用多少种方式组成该面值. 每种硬币的数量是无限的.典型完全背包. 状态 ...

  4. [LeetCode] Coin Change 硬币找零

    You are given coins of different denominations and a total amount of money amount. Write a function ...

  5. HDOJ 2069 Coin Change(母函数)

    Coin Change Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  6. HDU 2069 Coin Change

    Coin Change Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...

  7. JSU省赛队员选拔赛个人赛1(Coin Change、Fibbonacci Number、Max Num、单词数、无限的路、叠筐)

    JSU省赛队员选拔赛个人赛1 一.题目概述: A.Coin Change(暴力求解.动态规划)     B.Fibbonacci Number(递推求解) C.Max Num(排序.比较) D.单词数 ...

  8. C - Coin Change (III)(多重背包 二进制优化)

    C - Coin Change (III) Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...

  9. Coin Change (IV) (dfs)

    Coin Change (IV) Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu [Subm ...

随机推荐

  1. PhpStorm+XAMPP+Xdebug 集成开发和断点调试环境配置

    0x01 Xdebug安装 参考:https://xdebug.org/docs/install cd xdebug-/ phpize sudo ./configure --enable-xdebug ...

  2. [贪心,dp] Educational Codeforces Round 71 (Rated for Div. 2) C. Gas Pipeline (1207C)

    题目:http://codeforces.com/contest/1207/problem/C   C. Gas Pipeline time limit per test 2 seconds memo ...

  3. Java GC(垃圾回收)机制知识总结

    目录 Java GC系列 Java关键术语 Java HotSpot 虚拟机 JVM体系结构 Java堆内存 启动Java垃圾回收 Java垃圾回收过程 垃圾回收中实例的终结 对象什么时候符合垃圾回收 ...

  4. BZOJ 4472 salesman 题解

    题目 某售货员小T要到若干城镇去推销商品,由于该地区是交通不便的山区,任意两个城镇之间都只有唯一的可能经过其它城镇的路线.小T可以准确地估计出在每个城镇停留的净收益.这些净收益可能是负数,即推销商品的 ...

  5. Ubuntu 18 安装MySQL 5.7

    1.首先把系统换到阿里云的镜像源,需要等待一会 2.系统更新完毕后执行MySQL安装命令:sudo apt install mysql-server 3.查看MySQL服务状态:sudo servic ...

  6. SpringCloud入门(九): Zuul 上传&回退&异常处理&跨域

    Zuul的上传 1.构建一个上传类 import org.springframework.web.bind.annotation.PostMapping; import org.springframe ...

  7. phpwind 安装下一步空白解决方案

    系统版本  centos 翻阅网上大部分都是php版本问题,让降级就行了,试了之后根本不行 其实再安装一个插件即可成功 如下: yum install -y php-mysql

  8. 全网独家:成长经历分享 & 我为什么要写书?

    在当今高速发展的移动互联网+云优先的时代,到处充斥着不可预知的变化,有的来自于客户需求的变化,有的来自于市场环境的变化,面对着这些变化,给企业在市场.渠道.产品.服务各方面都带来了一系列新的挑战,每个 ...

  9. idea运行javadoc生成文档以及 报错编码gbk的不可映射字符坑

    将项目类信息生成文档 idea整合了javadoc的操作,可以一键生成doc文档 方法: 选中你要生成文档的项目 点击上方tools->Generate JavaDoc 运行即可 注意这里有一个 ...

  10. Shell:Day10

    shell脚本:明白一点:shell脚本本身是一个工具 在写shell脚本之前,就要明白:这个功能能到底如何实现? curl 访问文件源代码,查看网站状态: 才能通过shell(bash)所提供的逻辑 ...