Description

The cows are going to space! They plan to achieve orbit by building a sort of space elevator: a giant tower of blocks. They have K (1 <= K <= 400) different types of blocks with which to build the tower. Each block of type i has height h_i (1 <= h_i <= 100) and is available in quantity c_i (1 <= c_i <= 10). Due to possible damage caused by cosmic rays, no part of a block of type i can exceed a maximum altitude a_i (1 <= a_i <= 40000).

Help the cows build the tallest space elevator possible by stacking blocks on top of each other according to the rules.

Input

* Line 1: A single integer, K

* Lines 2..K+1: Each line contains three space-separated integers: h_i, a_i, and c_i. Line i+1 describes block type i.

Output

* Line 1: A single integer H, the maximum height of a tower that can be built

Sample Input


Sample Output


Hint

OUTPUT DETAILS:

From the bottom: 3 blocks of type 2, below 3 of type 1, below 6 of type 3. Stacking 4 blocks of type 2 and 3 of type 1 is not legal, since the top of the last type 1 block would exceed height 40.

题解

题目大意:奶牛要去太空。为了实现这一目标,它们计划用k种石头建造一个高塔。每种石头有c个,每个高度为h,由于石头本身的质量问题,它们被放置的高度有一个限度,不能放在这一高度以上,记为a。求高塔可以达到的最大高度。
简单多重背包
#include<iostream>
#include<algorithm>
using namespace std;
int n;
bool f[];
struct block{
int h,c,a;
bool operator<(const block ano)const{
return a<ano.a;
}
}b[];
int main(){
ios::sync_with_stdio(false);
cin>>n;
for(int i=;i<=n;i++)
cin>>b[i].h>>b[i].a>>b[i].c;
sort(b+,b++n);
f[]=;
for(int i=;i<=n;i++)
for(int k=;k<=b[i].c;k++)
for(int j=b[i].a;j>=k*b[i].h;j--)
if(f[j-b[i].h])
f[j]=;
for(int j=;j>=;j--)
if(f[j]){
cout<<j<<endl;
break;
}
return ;
}

poj[2392]space elevator的更多相关文章

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

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

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

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

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

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

  4. POJ 2392 Space Elevator 贪心+dp

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

  5. POJ 2392 Space Elevator DP

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

  6. POJ 2392 Space Elevator 背包题解

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

  7. POJ 2392 Space Elevator(多重背包)

    显然塔的总高度不会超过最大的a[i],而a[i]之前的可以到达的高度 是由a值更小的块组成,所以按照a从小到大的顺序去转移. 然后就是多重背包判断存在性了,几乎和coin那题一样. 数据没coin丧病 ...

  8. BZOJ 1739: [Usaco2005 mar]Space Elevator 太空电梯

    题目 1739: [Usaco2005 mar]Space Elevator 太空电梯 Time Limit: 5 Sec  Memory Limit: 64 MB Description The c ...

  9. A - Space Elevator(动态规划专项)

    A - Space Elevator Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

随机推荐

  1. Web自动化测试 Selenium 3/3 https的配置

    Https的信任问题处理 具体步骤如下(以demo为例) 1) ./ca.sh : 使用默认的服务器192.168.1.1的证书 ./ca.sh IP : 使用IP设置的证书 2) 以上运行后把 ge ...

  2. Android根据字符串加载Activity和图片

    根据传入的字符串跳转Activity Intent intent = new Intent(context,Class.forName("com.packname.Activity" ...

  3. 【代码笔记】iOS-判断textField里面是否有空

    一,效果图. 二,工程图. 三,代码. ViewController.m - (void)viewDidLoad { [super viewDidLoad]; // Do any additional ...

  4. mysql GROUP BY 与 ORDER BY 查询不是最新记录

    转载:http://blog.csdn.net/qvbfndcwy/article/details/7200910 鉴于项目的需要,就从网上找到该文章,文章分析得很详细也很易懂,在android里,( ...

  5. db2简单语句记录

    db2start db2 connect reset 断开连接 db2 drop db xxx 删除数据库 db2 list tables 查看表 db2 create database xxx 建立 ...

  6. redmine 安装

    现在redmine安装部署的方法有很多,有安装包,docker,虚拟机镜像,还可以在ubuntu,centos中添加安装源. 但是最好维护方法还是从源码去部署. 一. 目标环境: 1. Redmine ...

  7. Grunt安装配置教程:前端自动化工作流

    Grunt这货是啥? Grunt 是一个基于任务的 JavaScript 项目命令行构建工具. 最近很火的前端自动化小工具,基于任务的命令行构建工具 http://gruntjs.com Grunt能 ...

  8. mysql常用函数汇总

    一.数学函数ABS(x)   返回x的绝对值BIN(x)   返回x的二进制(OCT返回八进制,HEX返回十六进制)CEILING(x)   返回大于x的最小整数值EXP(x)   返回值e(自然对数 ...

  9. Axure RP7.0 使用记录手册

    第一章   Axure RP7.0 下载,汉化与注册教程 一.下载软件 Axure官网:http://www.axure.com/ Axure教程官网:http://www.iaxure.com/ 网 ...

  10. Flex各类型坐标转换(全局、本地、内容坐标间转换)

    Flex包含3种坐标:全局坐标.本地坐标.内容坐标 全局坐标:stage级别,坐标原点为舞台的左上角,如MouseEvent的stageX.stageY坐标. 本地坐标:组件级别的坐标系,相对坐标,坐 ...