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 这个是背包问题中  最小值问题

最新文章

  1. Android Weekly Notes Issue #226
  2. ceph calamari 监控系统安装 on ubuntu 14.04
  3. Unity3D项目开发一点经验
  4. ASP.NET四则运算--工厂模式
  5. HTML5自学笔记[ 1 ]新增标签
  6. getDefinitionByName与ApplicationDomain.getDefinition
  7. Struts1运行原理以及整合步骤
  8. Centos安装编译环境
  9. 有关JAVA基础学习中的集合讨论
  10. 普林斯顿大学算法课 Algorithm Part I Week 3 快速排序 Quicksort
  11. [LeetCode][Python]16: 3Sum Closest
  12. 隐藏AutoCompleteTextView下拉框的滚动条
  13. Android——与查询联系人相关的3张表
  14. 关于ajax跨域问题
  15. JS复习:第六章
  16. Linux中检查本地系统上的开放端口列表的方法
  17. Stackoverflow热门问题
  18. Java高并发--AQS
  19. django 一个关于分组查询的问题分析
  20. Android Dalvik虚拟机初识

热门文章

  1. RMQ Tarjan的Sparse-Table算法
  2. 【HDU5934】Bomb——有向图强连通分量+重建图
  3. python-文本字符串
  4. JUnit 5基础指南
  5. 单元测试实践思考(junit5+jmockit+testcontainer)
  6. 开始 Keras 序列模型(Sequential model)
  7. 【SQL SERVER】锁机制
  8. [POJ1835]宇航员&lt;模拟&gt;
  9. [洛谷1649]障碍路线&lt;BFS&gt;
  10. Unity引擎入门——制作第一个2D游戏(2)角色移动与动画