poj 2392 Space Elevator(多重背包+先排序)
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 ( <= K <= ) different types of blocks with which to build the tower. Each block of type i has height h_i ( <= h_i <= ) and is available in quantity c_i ( <= c_i <= ). Due to possible damage caused by cosmic rays, no part of a block of type i can exceed a maximum altitude a_i ( <= a_i <= ). Help the cows build the tallest space elevator possible by stacking blocks on top of each other according to the rules.
Input
* Line : A single integer, K * Lines ..K+: Each line contains three space-separated integers: h_i, a_i, and c_i. Line i+ describes block type i.
Output
* Line : A single integer H, the maximum height of a tower that can be built
Sample Input
Sample Output
Hint
OUTPUT DETAILS: From the bottom: blocks of type , below of type , below of type . Stacking blocks of type and of type is not legal, since the top of the last type block would exceed height .
Source
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
using namespace std;
#define N 406
#define M 40006
struct Node{
int h,a,c;
}block[N];
int dp[M*N];
bool cmp(Node a,Node b){
return a.a<b.a;
}
int main()
{
int n;
while(scanf("%d",&n)==){
for(int i=;i<n;i++){
scanf("%d%d%d",&block[i].h,&block[i].a,&block[i].c);
}
sort(block,block+n,cmp); memset(dp,-,sizeof(dp));
dp[]=;
for(int i=;i<n;i++){
for(int j=;j<=M;j++){
if(dp[j]>=){
dp[j]=block[i].c;
}
else if(j<block[i].h || dp[j-block[i].h]<=){
dp[j]=-;
}
else if(j>block[i].a){
dp[j]=-;
}
else{
dp[j]=dp[j-block[i].h]-;
}
}
}
for(int i=M;i>=;i--){
if(dp[i]!=-){
printf("%d\n",i);
break;
}
} }
return ;
}
poj 2392 Space Elevator(多重背包+先排序)的更多相关文章
- 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 ...
- POJ 2392 Space Elevator(多重背包)
显然塔的总高度不会超过最大的a[i],而a[i]之前的可以到达的高度 是由a值更小的块组成,所以按照a从小到大的顺序去转移. 然后就是多重背包判断存在性了,几乎和coin那题一样. 数据没coin丧病 ...
- POJ 2392 Space Elevator 背包题解
多重背包.本题不须要二分优化.相对简单点.由于反复数十分小,小于10. 而添加一个限制每种材料的高度做法.假设使用逆向填表,那么仅仅须要从这个高度往小递归填表就能够了. 还有就是注意要排序,以限制高度 ...
- poj2392 Space Elevator(多重背包)
http://poj.org/problem?id=2392 题意: 有一群牛要上太空.他们计划建一个太空梯-----用一些石头垒.他们有K种不同类型的石头,每一种石头的高度为h_i,数量为c_i,并 ...
- 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 DP
该题与POJ 1742的思路基本一致:http://www.cnblogs.com/sevenun/p/5442279.html(多重背包) 题意:给你n个电梯,第i个电梯高h[i],数量有c[i]个 ...
- POJ 2392 Space Elevator 贪心+dp
题目链接: http://poj.org/problem?id=2392 题意: 给你k类方块,每类方块ci个,每类方块的高度为hi,现在要报所有的方块叠在一起,每类方块的任何一个部分都不能出现在ai ...
- poj 1742 Coins (多重背包)
http://poj.org/problem?id=1742 n个硬币,面值分别是A1...An,对应的数量分别是C1....Cn.用这些硬币组合起来能得到多少种面值不超过m的方案. 多重背包,不过这 ...
随机推荐
- [Android开发常见问题-14] Unexpected namespace prefix "abc" found for tag SomeThing
很多开发者朋友可能会自己定义一些控件,以此来扩展现有控件的功能,在扩展空间的时候通常会自己定义一些属性,例如: [html] view plain copy <android.alex.v ...
- 【蓝桥杯】PREV-5 错误票据
题目链接:gpid=T28">http://lx.lanqiao.org/problem.page? gpid=T28 历届试题 错误票据 时间限制:1.0s 内存限制:2 ...
- 我对Laravel ThinkPHP Yii symfony2 CI cakephp 的看法
这是我的真心体会,在尝试使用Laravel.ThinkPHP.Yii.symfony2.CI.cakephp.Yii2 之后的真实想法(default7#zbphp.com). 1)ThinkPHP ...
- Android 使用ViewPager实现左右循环滑动图片
ViewPager这个小demo实现的是可以左右循环滑动图片,下面带索引,滑到最后一页在往右滑动就要第一页,第一页往左滑动就到最后一页,先上效果图,用美女图片是我一贯的作风,呵呵 1. 首先看一 ...
- IOS成长之路-Nsstring中搜索方法rangeOfString
NSString *str1 = @"can you \n speak English"; NSString *str = @"\n"; //在str1这个字符 ...
- MySQL数据库的环境及简单操作
***********************************************声明*************************************************** ...
- Sybase datetime 时间转换格式 convert(varchar(10),字段名,转换格式)
convert(varchar(10),字段名,转换格式)sybase下convert函数第三个参数(时间格式)比如:1.select user_id,convert(varchar(10),dayt ...
- Draggable(拖动)组件
一.加载方式 //class 加载方式 <div id="box" class="easyui-draggable" style="width: ...
- <httpProtocol/>配置http协议头
Web.Config中的位置 <configuration> <system.webServer> <httpProtocol> <!--http协议内容-- ...
- c - 每位数字尾部加空格
/* input:一个4位整数. output:每位整数后紧跟一个空格的字符串. */ char * insert(char *s) { int len = strlen(s); * len + ); ...