显然塔的总高度不会超过最大的a[i],而a[i]之前的可以到达的高度

是由a值更小的块组成,所以按照a从小到大的顺序去转移。

然后就是多重背包判断存在性了,几乎和coin那题一样。

数据没coin丧病,倍增可过,单调队列也可,不过还是优化定义最好写。

#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
//#include<bits/stdc++.h>
using namespace std; const int maxk = , maxh = 4e4+;
struct Block
{
int h, a, c;
bool operator <(const Block& th) const{
return a < th.a;
}
void IN(){ scanf("%d%d%d",&h,&a,&c); }
}B[maxk]; int f[maxh]; //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
int k;
scanf("%d",&k);
for(int i = k; i--;) B[i].IN();
sort(B,B+k);
int ans = ;
memset(f+,-,sizeof(int)*B[k-].a);
for(int i = ; i < k; i++){
for(int j = ; j <= B[i].a; j++){
if(~f[j]) f[j] = B[i].c;
else if(j>=B[i].h && f[j-B[i].h] > ){
f[j] = f[j-B[i].h] - ;
ans = max(j,ans);
}else f[j] = -;
}
}
printf("%d\n",ans);
return ;
}

POJ 2392 Space Elevator(多重背包)的更多相关文章

  1. poj 2392 Space Elevator(多重背包+先排序)

    Description The cows are going to space! They plan to achieve orbit by building a sort of space elev ...

  2. POJ 2392 Space Elevator(多重背包变形)

    Q: 额外添加了最大高度限制, 需要根据 alt 对数据进行预处理么? A: 是的, 需要根据 alt 对数组排序 Description The cows are going to space! T ...

  3. POJ 2392 Space Elevator(贪心+多重背包)

    POJ 2392 Space Elevator(贪心+多重背包) http://poj.org/problem?id=2392 题意: 题意:给定n种积木.每种积木都有一个高度h[i],一个数量num ...

  4. POJ 2392 Space Elevator 背包题解

    多重背包.本题不须要二分优化.相对简单点.由于反复数十分小,小于10. 而添加一个限制每种材料的高度做法.假设使用逆向填表,那么仅仅须要从这个高度往小递归填表就能够了. 还有就是注意要排序,以限制高度 ...

  5. poj[2392]space elevator

    Description The cows are going to space! They plan to achieve orbit by building a sort of space elev ...

  6. poj2392 Space Elevator(多重背包)

    http://poj.org/problem?id=2392 题意: 有一群牛要上太空.他们计划建一个太空梯-----用一些石头垒.他们有K种不同类型的石头,每一种石头的高度为h_i,数量为c_i,并 ...

  7. POJ 2392 Space Elevator DP

    该题与POJ 1742的思路基本一致:http://www.cnblogs.com/sevenun/p/5442279.html(多重背包) 题意:给你n个电梯,第i个电梯高h[i],数量有c[i]个 ...

  8. POJ 2392 Space Elevator 贪心+dp

    题目链接: http://poj.org/problem?id=2392 题意: 给你k类方块,每类方块ci个,每类方块的高度为hi,现在要报所有的方块叠在一起,每类方块的任何一个部分都不能出现在ai ...

  9. poj 1742 Coins (多重背包)

    http://poj.org/problem?id=1742 n个硬币,面值分别是A1...An,对应的数量分别是C1....Cn.用这些硬币组合起来能得到多少种面值不超过m的方案. 多重背包,不过这 ...

随机推荐

  1. java笔试面试题准备

    J2SE基础 九种基本数据类型的大小,以及它们的封装类 byte 8 Byte char 16 Character short 16 Short int 32 Integer long 64 Long ...

  2. Educational Codeforces Round 64 (Rated for Div. 2)D(并查集,图)

    #include<bits/stdc++.h>using namespace std;int f[2][200007],s[2][200007];//并查集,相邻点int find_(in ...

  3. python之02数据类型学习

    参考链接:http://www.cnblogs.com/yuanchenqi/articles/5782764.html python的数据类型有:Number.Boolean.String .Lis ...

  4. java知识点积累(一)

    知识点积累 1.关于final的重要知识点: final关键字可以用于成员变量.本地变量.方法以及类: final修饰的成员变量必须在声明时被初始化,或者在构造器中初始化,否则就会报编译错误: 不能够 ...

  5. Spark Runtime概述

    从Spark Runtime的角度来讲由五大核心对象:Master.Worker.Executor.Driver.CoarseGrainedExecutorBacked: Spark在做分布式集群系统 ...

  6. 帝都Day4(3)——还是数据结构

    可并堆 左偏树中 dist[x]=dist[rs[x]]+1 合并的时候,把权志较大的根作为根节点,把这棵树右子树和另一棵树合并. 说明白点:(上图描述有点问题) 设x表示根权值较大的左偏树,y表示根 ...

  7. chromedriver对应chrom版本

    chromedriver版本 支持的Chrome版本 v2.37 v64-66 v2.36 v63-65 v2.35 v62-64 v2.34 v61-63 v2.33 v60-62 v2.32 v5 ...

  8. C++11随机数发生器

    前言 一直知道所谓的"随机数"都是伪随机,事实上也是满足某种规则生成的.有些程序测试时通常需要一个随机数源,但在新标准出现之前,C++都是依赖简单的C库函数rand来生成随机数的. ...

  9. python 用turtle 画小猪佩奇

    from turtle import * def nose(x,y):#鼻子 penup()#提起笔 goto(x,y)#定位 pendown()#落笔,开始画 setheading(-30)#将乌龟 ...

  10. Docker 镜像制作 CentOS+JDK+Tomcat

    [root@localhost createImages]# ls apache-tomcat-.tar.gz server-jre-8u121-linux-x64.tar.gz [root@loca ...