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. SharePoint 2013 版本号和相关问题介绍

    今天查SharePoint 补丁,无意间发现一个非常好的链接,分享给大家! 这里面有SharePoint近期的版本号,而且不断更新,还有每个补丁可能带来的问题,对于服务器经常需要打补丁的那是非常有用, ...

  2. 渗透测试常规思路分析-FREEBUF

    最基础但练得好最后也非常厉害 1.  主要由于服务器配置等原因造成的信息泄露 常用google ,bing等搜索工具,轻量级的搜索出一些遗留后门,不想被发现的后台入口,中量级的搜索出一些用户信息泄露, ...

  3. 教新手一步步解决:Plugin is too old, please update to a more recent version, or set ANDROID_DAILY_OVERRIDE environment variable to和更新gradle问题

    android studio出现问题:Plugin is too old, please update to a more recent version, or set ANDROID_DAILY_O ...

  4. Android studio .9图片造成的错误总结

    前言,今天早晨遇到一个很奇葩的问题,导致我花费了很长的时间来解决.从eclipse 项目里复制过来4张.9图片,粘贴到android studio 项目里, 一运行发现报错,开始是 找不到这几张.9图 ...

  5. Android.mk相关知识

    Android.mk是Android提供的一种makefile文件,用来指定诸如编译生成so库名.引用的头文件目录.需要编译的.c/.cpp文件和.a静态库文件等.要掌握jni,就必须熟练掌握Andr ...

  6. 使用TARGET_IPHONE_SIMULATOR和TARGET_OS_IPHONE宏区分模拟器和设备

    #if TARGET_IPHONE_SIMULATOR          NSLog(@"run on simulator");      #else          NSLog ...

  7. objective-c系列-NSMutableString

    ********************************************** NSMutableString为NSString的子类,除了父类的方法,NSMutableStirng还有 ...

  8. iOS开发之AFN的基本使用

    本篇将从四个方面对iOS开发中经常使用到的AFNetworking框架进行讲解: 一.什么是 AFN 二.为什么要使用 AFN 三.AFN 怎么用 三.AFN和ASI的区别 一.什么是 AFN AFN ...

  9. PHPMailer不能发送邮件

    PHPMailer不能连接SMTP服务器,和修改SMTP大小写没有关系 (2011-10-22 12:17:35) 转载▼ 标签: php phpmailer 杂谈 分类: 默认分类 PHPmaile ...

  10. html中相似的标签、属性的区别

    [1]<i></i> 和 <em></em>标签 相同:都是表示斜体. 区别: (1)<em>表示被强调呈现的内容,<i>是物理 ...