POJ-1276 Cash Machine(多重背包问题)
来源:互联网 发布:golang defer func 编辑:程序博客网 时间:2024/05/21 11:21
题目链接:点击打开链接
题意:
给你争取要获得的钱数, 货币种类和每种货币的数量, 求在不超过给的钱数的情况下,获得尽量多的钱。
思路:
还是应用一般的状态转移方程:dp[j] = min(dp[j - d[i] ] + d[i],dp[j[);
处理个数不超过n[i]的方法是另加一个book数组,标记一下。详情看代码:
代码:
#include <iostream>#include <string.h>using namespace std;int n[11], d[11], dp[100001], book[100001];int main(){ int cash; while(cin>>cash){memset(dp,0,sizeof(dp));int N;cin>>N;for(int i = 0;i < N;i++)cin>>n[i]>>d[i];for(int i = 0;i < N;i++){memset(book,0,sizeof(book));for(int j = d[i];j <= cash;j++)if(dp[j] < dp[j - d[i] ] + d[i] && book[j- d[i] ] < n[i]){dp[j] = dp[j - d[i] ] + d[i];book[j] = book[j-d[i] ] + 1;}}cout<<dp[cash]<<endl;} return 0;}
0 0
- POJ 1276 Cash Machine 多重背包问题
- POJ 题目1276 Cash Machine(多重背包问题)
- POJ 1276 Cash Machine(多重背包问题)
- POJ-1276 Cash Machine(多重背包问题)
- POJ 1276 Cash Machine (多重背包)
- POJ 1276 Cash Machine (多重背包)
- 【POJ】1276 Cash Machine(多重背包)
- poj 1276 Cash Machine(多重背包)
- poj 1276 Cash Machine(多重背包)
- POJ - 1276 Cash Machine(多重背包)
- POJ 1276 - Cash Machine(多重背包)
- POJ 1276 Cash Machine(多重背包)
- POJ 1276 Cash Machine(多重背包)
- POJ 1276 Cash Machine (多重背包)
- POJ-1276-Cash Machine(多重背包)
- POJ 1276 Cash Machine(多重背包)
- Cash Machine poj 1276(多重背包)
- poj 1276 Cash Machine (多重背包)
- HDU 3493 The Little Architect【矩阵快速幂
- 十大机器学习算法之支持向量机(三)
- 多线程(四)线程的同步之线程安全问题
- Effective c++ 第一章总结
- Spark安装与环境配置
- POJ-1276 Cash Machine(多重背包问题)
- BZOJ3450 Tyvj1952 Easy
- mysql能用localhost连接不能使用127.0.0.1连接的问题之一
- 树-堆结构练习——合并果子之哈夫曼树
- cpu测试
- “Several ports ( 8088, 8009) required by Tomcat v6.0 Server at localhost are already in use. The ser
- (三十五)、File类
- Fox And Two Dots
- 三、SQLite数据库