POJ 2392 Space Elevator 多重背包
来源:互联网 发布:net.cn域名 编辑:程序博客网 时间:2024/05/21 11:10
题意:牛们想造一个尽可能高的塔。他们有N种方块,每种方块高h_i,有c_i个,但是这种方块只能在高度小于a_i时使用。问这个塔最高可以搭起到多高的高度。
思路:没有高度限制的话,其实把所有的方块都用上,才是最高的高度。但是有了高度a_i限制后,就变成了容量限制的多重背包。
可以注意到,方块还要考虑摆放的顺序问题,不同的摆放顺序也会让塔的高度不一样。这样,我们就想能否按照高度a_i从小到大进行排序。即a_i越小的先放。
这是中贪心的想法,可以证明这样做不会失去最优解。
剩下的就是个多重背包了。
代码如下:
#include <cstdio>#include <algorithm>#include <cstring>using namespace std;const int MAX = 200010;struct node{ int h,a,c; node(){} bool operator < (const node & rhs) const{ return a < rhs.a; }} ev[500];int dp[MAX];int main(void){ //freopen("input.txt","r",stdin); int K; scanf("%d",&K); for(int i = 0; i < K; ++i) scanf("%d%d%d",&ev[i].h,&ev[i].a,&ev[i].c); sort(ev,ev+K); dp[0] = 1; int ans = 0; for(int i = 0; i < K; ++i){ int num = ev[i].c; for(int k = 1; num; k <<= 1){ int mul = min(k,num); for(int j = ev[i].a ; j >= mul * ev[i].h; --j) if(dp[j- ev[i].h*mul]) dp[j] = 1,ans = max(j,ans); num -= mul; } } printf("%d\n",ans); return 0;}
0 0
- poj 2392 Space Elevator 多重背包
- poj 2392 Space Elevator(多重背包变形)
- 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 dp 多重背包
- poj Space Elevator 2392 (多重背包)
- 多重背包-POJ 2392 Space Elevator
- 开博庆贺
- 【Flume】【源码分析】flume中ExecSource源码的详细分析——执行终端命令获取数据
- SQL基础(二)
- 银行家算法
- Response Redirect(代码强制跳转)
- POJ 2392 Space Elevator 多重背包
- Error changing the ports in Mamp
- 未发布的IOS应用App生成ipa进行内部下载测试(Testflight、fir.im)
- 轻松解决oracle11g 空表不能 exp 导出 的问题。
- 数据库访问层中使用GenericDao和HibernateDaoSupport
- u盘启动cdlinux系统利用pin破解wifi密码 亲测成功
- 优化网站加载速度的14个技巧
- 以 MAMP 为 Mac OS X 安装并设置 PHP开发环境
- LeetCode OJ 之 Substring with Concatenation of All Words(有所有单词组合的子串)