poj 1276 Cash Machine
来源:互联网 发布:中国联通4g网络设置 编辑:程序博客网 时间:2024/06/03 15:18
题目链接: 点击打开链接
#include <cstdio>#include <memory.h>#include <algorithm>using namespace std;const int maxc = 100000 + 10;const int maxn = 20;int V, n, cost[maxn], amount[maxn], dp[maxc];void ZeroOnePack(int cost, int value){for (int i = V; i >= cost; --i)dp[i] = max(dp[i], dp[i - cost] + value);}void ComPack(int cost, int value){for (int i = cost; i <= V; ++i)dp[i] = max(dp[i], dp[i - cost] + value);}void MulPack(int cost, int value, int amount){if (cost * amount > V) {ComPack(cost, value);return;}for (int i = 1; i <= amount; i <<= 1) {ZeroOnePack(cost * i, value * i);amount -= i;}ZeroOnePack(cost * amount, value * amount);}void solve(){memset(dp, 0, sizeof(dp));for (int i = 1; i <= n; ++i)MulPack(cost[i], cost[i], amount[i]);}int main(){while (scanf("%d", &V) == 1){scanf("%d", &n);for (int i = 1; i <= n; ++i)scanf("%d %d", &amount[i], &cost[i]);solve();printf("%d\n", dp[V]);}return 0;}
0 0
- poj 1276 Cash Machine
- poj 1276 Cash Machine
- poj 1276Cash 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-1276Cash 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
- 大数据统计分析公司介绍-决策树
- 数据结构 二叉排序树
- FZU - 2038 Another Postman Problem
- 判断二叉树是否为二叉搜索树BST
- jbpm4.4集成入SSH项目中
- poj 1276 Cash Machine
- Finagle:一个支持多协议的RPC系统
- 实现物体的方向跟着拖拽的方向
- yum 命令
- Launcher2<一>
- Hadoop、HBase配置Ganglia指南(metrics1)
- Ant 构建Solr过程中checksum出错的问题
- Daily article(4)
- 如何利用Javap工具对.class文件进行查看