太空电梯

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

  这题就是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. BZOJ-2186 沙拉公主的困惑 线性筛(筛筛筛)+线性推逆元

    2186: [Sdoi2008]沙拉公主的困惑 Time Limit: 10 Sec Memory Limit: 259 MB Submit: 2417 Solved: 803 [Submit][St ...

  2. 【bzoj1050】 旅行comf

    http://www.lydsy.com/JudgeOnline/problem.php?id=1050 (题目链接) 题意 给出一个无向图,求图中两点间某条路径使得最大权值除以最小权值的值最小 So ...

  3. poj 3683 2-SAT入门

    原题模型:两者(A,B)不能同时取 #include "cstdio" #include "vector" #include "stack" ...

  4. POJ2299Ultra-QuickSort(归并排序 + 树状数组求逆序对)

    树状数组求逆序对   转载http://www.cnblogs.com/shenshuyang/archive/2012/07/14/2591859.html 转载: 树状数组,具体的说是 离散化+树 ...

  5. PHP高效率写法(详解原因)

    1.尽量静态化: 如果一个方法能被静态,那就声明它为静态的,速度可提高1/4,甚至我测试的时候,这个提高了近三倍.当然了,这个测试方法需要在十万级以上次执行,效果才明显.其实静态方法和非静态方法的效率 ...

  6. 快速tab应用

    ZCTabNav-master https://github.com/zcsoft/ZCTabNav 层次构架清楚,很适合快速,导入

  7. python之字符聊天小工具

    server side: # coding: gb2312#socket server端#获取socket构造及常量from socket import *#''代表服务器为localhostmyHo ...

  8. Iterator<转>

    Iterator就是迭代器的意思. Iterator是一个接口,利用迭代器主要是获取元素,很少删除元素.有三个方法:    1)hasNext():判断是否有更多的元素,如果有返回true.    2 ...

  9. WCF 客户端解决大数据量传输配置

    1. 服务端返回数据给客户端报错 在客户端配置文件中,主要是配置maxReceivedMessageSize <system.serviceModel> <bindings> ...

  10. ubuntu.sh: 113: ubuntu.sh: Syntax error: "(" unexpected

    在ubuntu电脑上安装lnmp环境,执行下面命令时 sudo sh ubuntu.sh 报错误:ubuntu.sh: 113: ubuntu.sh: Syntax error: "(&qu ...