POJ2392 Space Elevator
题目:http://poj.org/problem?id=2392
一定要先按高度限制由小到大排序!
不然就相当于指定了一个累加的顺序,在顺序中是不能做到“只放后面的不放前面的”这一点的!
数组是四十万,不是四万。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,v[],l[],cnt,mx;
bool d[];
struct Node{
int c,a,h;
}r[];
void fen(int k)
{
int tmp=,mul=;
while(mul<=r[k].c)
{
v[++cnt]=tmp*r[k].h;
l[cnt]=r[k].a;
// printf("v=%d l=%d ",v[cnt],l[cnt]);
// printf("cnt=%d\n",cnt);
tmp<<=;
mul+=tmp;
}
int res=r[k].c-(mul-tmp);
if(res)
{
v[++cnt]=res*r[k].h;
l[cnt]=r[k].a;
// printf("v=%d l=%d cnt=%d\n",v[cnt],l[cnt],cnt);
}
}
bool cmp(Node a,Node b){return a.a<b.a;}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d%d%d",&r[i].h,&r[i].a,&r[i].c),mx+=r[i].c*r[i].h;
sort(r+,r+n+,cmp);
for(int i=;i<=n;i++)
fen(i);
d[]=;
for(int i=;i<=cnt;i++)
for(int j=l[i];j>=v[i];j--)
if(!d[j]&&j<=l[i])
{
// printf("j=%d v[i]=%d ",j,v[i]);
d[j]|=d[j-v[i]];
// printf("d[j]=%d\n",d[j]);
}
for(int i=mx;i>=;i--)
if(d[i])
{
printf("%d",i);
return ;
}
}
POJ2392 Space Elevator的更多相关文章
- poj2392 Space Elevator(多重背包问题)
Space Elevator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8569 Accepted: 4052 ...
- poj2392 Space Elevator(多重背包)
http://poj.org/problem?id=2392 题意: 有一群牛要上太空.他们计划建一个太空梯-----用一些石头垒.他们有K种不同类型的石头,每一种石头的高度为h_i,数量为c_i,并 ...
- POJ2392:Space Elevator
Space Elevator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9244 Accepted: 4388 De ...
- poj[2392]space elevator
Description The cows are going to space! They plan to achieve orbit by building a sort of space elev ...
- poj 2392 Space Elevator(多重背包+先排序)
Description The cows are going to space! They plan to achieve orbit by building a sort of space elev ...
- BZOJ 1739: [Usaco2005 mar]Space Elevator 太空电梯
题目 1739: [Usaco2005 mar]Space Elevator 太空电梯 Time Limit: 5 Sec Memory Limit: 64 MB Description The c ...
- A - Space Elevator(动态规划专项)
A - Space Elevator Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- POJ 2392 Space Elevator(多重背包变形)
Q: 额外添加了最大高度限制, 需要根据 alt 对数据进行预处理么? A: 是的, 需要根据 alt 对数组排序 Description The cows are going to space! T ...
- POJ 2392 Space Elevator(贪心+多重背包)
POJ 2392 Space Elevator(贪心+多重背包) http://poj.org/problem?id=2392 题意: 题意:给定n种积木.每种积木都有一个高度h[i],一个数量num ...
随机推荐
- 开启turbine收集hystrix指标功能
使用turbine收集hystrix指标 1.pom中引入对turbin的依赖,并增加dashboard图形界面的展示 <dependencies> <dependency> ...
- httpclient cookie使用介绍
COOKIE的处理 session的保持是通过cookie来维持的,所以如果用户有勾选X天免登陆,这个session就X天内一直有效,就是通过这个cookie来维持. 如果没有选中x天免登陆,基本上就 ...
- linux pipes
In Linux, a pipe is implemented using two filedata structures which both point at the same temporary ...
- learning docker steps(1) ----- docker 安装
docker 安装 参考:https://docs.docker.com/install/linux/docker-ce/ubuntu/ 按如下指令可安装: $ sudo apt-get instal ...
- HDU 4802 && HDU 4803 贪心,高精 && HDU 4804 轮廓线dp && HDU 4805 计算几何 && HDU 4811 (13南京区域赛现场赛 题目重演A,B,C,D,J)
A.GPA(HDU4802): 给你一些字符串对应的权重,求加权平均,如果是N,P不计入统计 GPA Time Limit: 2000/1000 MS (Java/Others) Memory ...
- Delphi 项目 结构 文件夹 组织
Delphi Project Structure Folder Organization http://delphi.about.com/od/delphitips2008/qt/project_la ...
- Kafka生产者APi
kafka客户端发布record(消息)到kafka集群. 新的生产者是线程安全的,在线程之间共享单个生产者实例,通常单例比多个实例要快. 一个简单的例子,使用producer发送一个有序的key/v ...
- LeetCode OJ:Insert Interval
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessa ...
- settype和gettype
settype — 设置变量的类型 <?php$foo = "5bar"; // string$bar = true; // boolean settype($foo, ...
- 06-python opencv 使用摄像头捕获视频并显示
https://blog.csdn.net/huanglu_thu13/article/details/52337013