Space Elevator
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 9970   Accepted: 4738

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

3
7 40 3
5 23 8
2 52 6

Sample Output

48

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.

题意:奶牛想上太空给顶n种梯子,每种梯子对应三个值,a,h,c,a表示这种梯子必须在小于等于a的高度内使用,h表示它的高度,c表示这种梯子的个数。问内牛能够累出的最大高度。

分析:根据a从小到大排序,然后对于每一个找到背包容量为a的最大高度,可以用01背包处理,对每一个奶牛的梯子作为一个物品,物品的种数就是c;当然也可以用多重背包解

思路就是辣么简单就是没想出来,弱渣

 #include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
const int MAX = ;
int dp[MAX];
struct node
{
int h,a,c;
};
node cow[];
int cmp(node x, node y)
{
return x.a < y.a;
} int main()
{
int k;
while(scanf("%d", &k) != EOF)
{
for(int i = ; i < k; i++)
{
scanf("%d%d%d",&cow[i].h,&cow[i].a,&cow[i].c);
}
memset(dp,,sizeof(dp));
sort(cow, cow + k, cmp);
for(int i = ; i < k; i++)
{
for(int t = ; t <= cow[i].c; t++)
{
for(int j = cow[i].a; j >= cow[i].h; j--)
{
if(dp[j] <= cow[i].a && dp[j - cow[i].h] + cow[i].h <= cow[i].a)
dp[j] = max(dp[j], dp[j - cow[i].h] + cow[i].h);
}
}
}
int ans = ;
for(int i = ; i <= cow[k - ].a; i++) //这一步还是在斌神那里得到的提示,太弱了
ans = max(ans, dp[i]);
printf("%d\n", ans);
}
return ;
}

POJ2392Space Elevator(贪心+背包)的更多相关文章

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

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

  2. 【bzoj4922】[Lydsy六月月赛]Karp-de-Chant Number 贪心+背包dp

    题目描述 给出 $n$ 个括号序列,从中选出任意个并将它们按照任意顺序连接起来,求以这种方式得到匹配括号序列的最大长度. 输入 第一行包含一个正整数n(1<=n<=300),表示括号序列的 ...

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

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

  4. HDU3466Proud Merchants(贪心&背包)

    http://acm.hdu.edu.cn/showproblem.php?pid=3466 题目大意是说n个物品每个物品的花费是p,但是如果你现在的钱少于q就买不了这个物品,每个物品的价值是v,求有 ...

  5. POJ 2392 Space Elevator 贪心+dp

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

  6. Installing Apps Kattis - installingapps (贪心 + 背包)

    Installing Apps Kattis - installingapps Sandra recently bought her first smart phone. One of her fri ...

  7. HDU 5303 Delicious Apples(贪心 + 背包 2015多校啊)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5303 Problem Description There are n apple trees plan ...

  8. bzoj4922 [Lydsy1706月赛]Karp-de-Chant Number 贪心+背包

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4922 题解 记录每一个串的没有匹配的右括号 \()\) 的数量为 \(a_i\),为匹配的左括 ...

  9. AT4120-[ARC096D]Sweet Alchemy【贪心,背包】

    正题 题目链接:https://www.luogu.com.cn/problem/AT4120 题目大意 给出\(n\)个物品和一个容量\(m\),第\(i\)个物品体积为\(c_i\).除了第一个物 ...

随机推荐

  1. JavaScript基于时间的动画算法

    转自:https://segmentfault.com/a/1190000002416071 前言 前段时间无聊或有聊地做了几个移动端的HTML5游戏.放在不同的移动端平台上进行测试后有了诡异的发现, ...

  2. BIO、NIO与NIO.2的区别与联系

    BIO.NIO.NIO.2之间的区别主要是通过同步/异步.阻塞/非阻塞来进行区分的 同步: 程序与操作系统进行交互的时候采取的是问答的形式 异步: 程序与操作系统取得连接后,操作系统会主动通知程序消息 ...

  3. vim常用命令汇总

    vim常用命令汇总: http://www.cnblogs.com/softwaretesting/archive/2011/07/12/2104435.html 定位 本行第一个字符 ctrl+$ ...

  4. dxut.h(29): fatal error C1083: Cannot open include file: 'dxsdkver.h': No such file or directory

    从网上download一个三维演示模型的软件编译发现报找不到dxsdkver.h文件,网上查阅这是MS的DirectX sdk中的库文件,于是先download DirectX SDK 安装之后,配置 ...

  5. [MetaHook] R_SparkEffect

    By hzqst void R_SparkEffect(float *pos, int count, int velocityMin, int velocityMax) { efx.R_SparkSt ...

  6. 点击事件touches与ios的手势UIGestureRecognizer

    .h文件 @property (weak,nonatomic) IBOutlet UILabel *messageLabel;@property (weak,nonatomic) IBOutlet U ...

  7. jquery实现文件异步上传

    前言 这里用了2个JS插件,一个是Jquery原生js,我的版本是jquery-1.7.2.min.js,另一个是jquery.form.js.这个form.js 是关键,不可少哦.另外, 我的服务器 ...

  8. 通过爬虫代理IP快速增加博客阅读量——亲测CSDN有效!

    写在前面 题目所说的并不是目的,主要是为了更详细的了解网站的反爬机制,如果真的想要提高博客的阅读量,优质的内容必不可少. 了解网站的反爬机制 一般网站从以下几个方面反爬虫: 1. 通过Headers反 ...

  9. 第三章 Js变量的作用域和匿名函数

    3.1 先看下面的事例: ①var temp=0; ②temp=0; 当js解析器检测到①这种情况的时候,解析器会为这个变量开辟一个内存空间,如果前面已经存在这个变量,就会把这个变量覆盖掉. 当解析器 ...

  10. Android--下拉框

    一. 实现效果图如下 Android 中的下拉框为Spinner 组件,其效果图如上图片 二. 实现代码 布局代码如下 <?xml version="1.0" encodin ...