太空电梯

  题目大意:一群牛想造电梯到太空,电梯都是由一个一个块组成的,每一种块不能超过这个类型的高度,且每一种块都有各自的高度,有固定数量,问最高能造多高。

  这题就是1742的翻版,对ai排个序就可以了

  (尼玛,我qsort排了n-1个数,wa半天不知所措)

 #include <iostream>
#include <functional>
#include <algorithm> using namespace std;
typedef struct _set
{
int h_i;
int max_h;
int count;
}Block;
int fcomp(const void *a, const void *b)
{
return (*(Block *)a).max_h - (*(Block *)b).max_h;
} static int dp[];
static Block B_Set[]; void Search(const int); int main(void)
{
int n;
while (~scanf("%d", &n))
{
if (n == ) continue;
for (int i = ; i <= n; i++)
scanf("%d%d%d", &B_Set[i].h_i, &B_Set[i].max_h, &B_Set[i].count);
qsort(B_Set, n + , sizeof(Block), fcomp);
Search(n);
}
return ;
} void Search(const int n)
{
int i, j;
memset(dp, -, sizeof(dp));
dp[] = ;
for (i = ; i <= n; i++)
{
if (B_Set[i].h_i == ) continue;
for (j = ; j < B_Set[i].h_i && j <= B_Set[i].max_h; j++)//先把前面的几个包确定下来
if (dp[j] != -)
dp[j] = B_Set[i].count;
for (; j <= B_Set[i].max_h; j++)
{
if (dp[j] == -)
{
if (dp[j - B_Set[i].h_i] <= )
continue;
else dp[j] = dp[j - B_Set[i].h_i] - ;
}
else dp[j] = B_Set[i].count;
}
}
for (int i = B_Set[n].max_h; i >= ; i--)
{
if (dp[i] >-)
{
printf("%d\n", i);
break;
}
}
}

DP:Space Elevator(POJ 2392)的更多相关文章

  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

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

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

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

  6. poj2392 Space Elevator(多重背包问题)

    Space Elevator   Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8569   Accepted: 4052 ...

  7. POJ2392:Space Elevator

    Space Elevator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9244   Accepted: 4388 De ...

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

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

  9. Building a Space Station POJ - 2031

    Building a Space Station POJ - 2031 You are a member of the space station engineering team, and are ...

随机推荐

  1. CSS中font-style的斜体属性Italic oblique的区别

    要搞清楚这个问题,首先要明白字体是怎么回事.一种字体有粗体.斜体.下划线.删除线等诸多属性.但是并不是所有字体都做了这些,一些不常用的字体,或许就只有个正常体,如果你用Italic,就没有效果了~这时 ...

  2. HDU 2255 奔小康发大财

    传送门 Solution: KM算法 关于KM算法有一篇极好的文档http://www.cse.ust.hk/~golin/COMP572/Notes/Matching.pdf Implementat ...

  3. 编译java文件,出错:Failed to establish a connection with the target VM

    helloword程序,所有java学习人员人生第一个程序,哎妈,基础太差,出错 public class Helloword{ public Helloword() { public static ...

  4. 使用SubLineText3

    一 Sublinetext3 1. Sublime Text3是一款跨平台的编辑器, 2. 安装网址: http://www.sublimetext.com/3 二 常用使用方法 1)打开控制台: V ...

  5. jquery ajax提交表单数据的两种方式

    http://www.kwstu.com/ArticleView/kwstu_201331316441313 貌似AJAX越来越火了,作为一个WEB程序开发者要是不会这个感觉就要落伍,甚至有可能在求职 ...

  6. PHP利用Filesystem函数实现操作缓存(生成,获取,删除操作)

    <?php class File{ //$key 相当于缓存文件的文件名 //$value 缓存数据 private $_dir;//定义默认路径 const EXT='.txt'; publi ...

  7. 初学Hibernate

    Hibernate 是完全ORM的,只需要对 对象 进行操作,生成底层SQL语句 优势:1.可以简化开发 2.性能好(原生的Hibernate性能很差,要使用它,需要进行优化),优化方式:一级缓存.二 ...

  8. aop注解

    注解 xml的直接配置 <aop:config proxy-target-class="false"> //切入点 <aop:pointcut expressio ...

  9. Java Socket 网络编程心跳设计概念

    Java Socket 网络编程心跳设计概念   1.一般是用来判断对方(设备,进程或其它网元)是否正常动行,一 般采用定时发送简单的通讯包,如果在指定时间段内未收到对方响应,则判断对方已经当掉.用于 ...

  10. ios开发@selector的函数如何传参数/如何传递多个参数

    不同的类会有不同的传递方式,参数名也不尽相同.如果是传单个参数的就不用集合,如果是传多个参数可以用类似nsarray,nsdictionary之类的集合传递.看下面例子: 例子1: 通过NSTimer ...