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 ...
随机推荐
- 教你一步一步用 Node.js 制作慕课网视频爬虫
转自:http://www.jianshu.com/p/d7631fc695af 开始 这个教程十分适合初学 Node.js 的初学者看(因为我也是一只初学的菜鸟~) 在这里,我就默认大家都已经在自己 ...
- iOS UI-Lable标签、NStimer定时器和RunLoop超级死循环
// 标签UILable -显示文字 // 1.创建标签 UILabel *lable = [[UILabel alloc] init]; // 2.设置标签的坐标和大小 [lable setFram ...
- 跟我一起学习ASP.NET 4.5 MVC4.0(二)
上一篇文章中(跟我一起学习ASP.NET 4.5 MVC4.0(一))我们基础的了解了一下ASP.NET MVC4.0的一些比较简单的改变,主要是想对于MVC3.0来说的.因为这一些列主要是要给ASP ...
- Osmocom-bb系统编译
Ubuntu 12.04.5 LTS i386环境下编译 sudu su --------------------------------------------------------------- ...
- This App does not have access to your photos or videos in iOS 9
出现这个总是由于info.plist文件内的CFBundleDisplayName没有值或者为空.把名称填进去就可以用了.
- C语言基础:内存 分类: iOS学习 c语言基础 2015-06-10 21:59 23人阅读 评论(0) 收藏
全局变量:定义在函数之外.(不安全) 局部变量;定义在函数之内. 内存的划分:1栈区 2堆区 3静态区(全局区) 4常量区 5代码区 栈区..静态区.常量区.代码区的数据都是由系统分配和释放 ...
- Java中生产者与消费者模式
生产者消费者模式 首先来了解什么是生产者消费者模式.该模式也称有限缓冲问题(英语:Bounded-buffer problem),是一个多线程同步问题的经典案例.该问题描述了两个共享固定大小缓冲区的线 ...
- SIM800C SIM卡唯一标识符ICCID
/******************************************************************************* * SIM800C SIM卡唯一标识符 ...
- python3获取当前目录和上级目录
d = path.dirname(__file__) #返回当前文件所在的目录 # __file__ 为当前文件 获得某个路径的父级目录: parent_path = os.path.dirname( ...
- JS经典面试题
自己总结了一些JS面试题 希望能够帮助正在找工作的程序猿(●´∀`●) 1.js 实现一个函数对javascript中json 对象进行克隆 var oldObject ="sdf" ...