poj 2392 Space Elevator dp 多重背包
来源:互联网 发布:google tensorflow应用 编辑:程序博客网 时间:2024/05/29 03:21
题目
题目链接:http://poj.org/problem?id=2392
题目来源:《挑战》练习题
简要题意:
K 种块,每种高度hi 有ci 个,顶部位置不能超过ai 求搭起来的最大高度。数据范围:
1⩽K⩽400;1⩽hi⩽100;1⩽ci⩽10;1⩽ai⩽40000
题解
实际上肯定是个多重背包咯。
对
ai 排序然后每轮以ai 为容量去做多重背包就行了。由于只要判断访问,可以使用一些poj 1742 题解这里面的优化技巧
实现
用普通的多重背包估计也是可以的,我没试过。
代码
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#include <cstring>#include <stack>#include <queue>#include <string>#include <vector>#include <set>#include <map>#define pb push_back#define mp make_pair#define all(x) (x).begin(),(x).end()#define sz(x) ((int)(x).size())#define fi first#define se secondusing namespace std;typedef long long LL;typedef vector<int> VI;typedef pair<int,int> PII;LL powmod(LL a,LL b, LL MOD) {LL res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}// headconst int N = 405;const int M = 4E4+5;struct Node { int lim, cnt, v; bool operator<(const Node &o) const { return lim < o.lim; }};Node a[N];bool dp[M];int cnt[M];int use[M];int main(){ int n, from; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d%d", &a[i].v, &a[i].lim, &a[i].cnt); } sort(a+1, a+n+1); dp[0] = true; for (int i = 1; i <= n; i++) { for (int j = a[i].v; j <= a[i].lim; j++) { from = j-a[i].v; if (dp[from] && !dp[j] && (use[from] != i || cnt[from] < a[i].cnt)) { dp[j] = true; cnt[j] = use[from] == i ? cnt[from]+1 : 1; use[j] = i; } } } for (int i = a[n].lim; ~i; i--) { if (dp[i]) { printf("%d\n", i); break; } } return 0;}
0 0
- POJ 2392 Space Elevator [DP 多重背包]
- poj 2392 Space Elevator dp 多重背包
- poj 2392 Space Elevator(dp 排序+多重背包)
- poj 2392 Space Elevator 多重背包
- poj 2392 Space Elevator(多重背包变形)
- POJ 2392 Space Elevator (多重背包)
- poj 2392 Space Elevator(排序+多重背包)
- POJ 2392 Space Elevator (多重背包问题)
- POJ 2392 Space Elevator 多重背包
- POJ 2392 Space Elevator (多重背包+优化)
- poj 2392 Space Elevator (多重背包)
- poj 2392 Space Elevator(多重背包)
- POJ 2392 Space Elevator 多重背包
- poj 2392 Space Elevator (多重背包)
- POJ 2392-Space Elevator(多重背包)
- POJ 2392 Space Elevator(贪心+多重背包)
- POJ 2392 Space Elevator 多重背包
- poj Space Elevator 2392 (多重背包)
- HDU 1560DNA sequence
- [iOS基础]从使用UIPopoverController到UIViewController弹出模态
- 如何手工释放linux内存
- 前期深入
- 在 Struts 2 中自定义支持 OGNL 的标签
- poj 2392 Space Elevator dp 多重背包
- 使用 RxAndroid 处理异步任务
- 自定义View绘制圆形进度条
- 人见人爱A-B
- 获取Android设备挂载的所有存储器
- SSH框架描述
- Fragment的addSharedElement方法简述
- 招聘会有感
- ViewGroup和View的事件传递原理