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. Nginx反向代理+负载均衡简单实现(https方式)

    背景:A服务器(192.168.1.8)作为nginx代理服务器B服务器(192.168.1.150)作为后端真实服务器 现在需要访问https://testwww.huanqiu.com请求时从A服 ...

  2. zabbix错误记录

    zabbix部署好,在使用一段时间后,出现了不少报错,在此简单做一记录.1)Zabbix监控界面报错“Lack of free swap space”解决公司线上部署的zabbix3.0的监控界面首页 ...

  3. Linux内核

    Linux内核配置.编译及Makefile简述 Hi,大家好!我是CrazyCatJack.最近在学习Linux内核的配置.编译及Makefile文件.今天总结一下学习成果,分享给大家^_^ 1.解压 ...

  4. C语言 指针与字符串

    C语言可以在栈区 or 堆区 or 全局区 存放字符串,字符串不单单是存储在全局区的. //字符串与指针 #include<stdio.h> #include<stdlib.h> ...

  5. 当 IDENTITY_INSERT 设置为 OFF 时,不能为表中的标识列插入显式值

    {"当 IDENTITY_INSERT 设置为 OFF 时,不能向表 'OrderList' 中的标识列插入显式值"} 对于这个异常可以从两个角度来处理:A:数据库执行语句  B: ...

  6. js window.open()实现打印,如何在关闭打印窗口时刷新父窗口

    var childWin = window.open("your URL"); //获取子窗口句柄childWin.onunload = function(){ //onunloa ...

  7. [C++] 如何查看DLL有哪些函数

    Visual Studio里面自带了一个工具 dumpbin. 打开VS的command line,输入dumpbin可以查看帮助. 我们查看导出函数的话,使用选项/EXPORTS. 如果函数太多,可 ...

  8. IT男的”幸福”生活"续5

    各位哥们姐妹们,好,嗯,好.很多回复还是提到[IT男的”幸福”生活"]是小说来着剧情不真实,我还是免为其难的说一下吧.是真的回忆录,具体的事情都有.人也是真实的.在这里还是谢谢,这几天一直关 ...

  9. 微信小程序「官方示例代码」浅析【上】

    从某个微信群里,拿到了这个IDE的下载地址,然后就有了这个: 根本登不上去,怎么办,怎么办呢? 看代码啊... 反正我又没有保密协议,解压缩一看NodeWebkit + React: 好啦 ,逛逛呗, ...

  10. vitualbox 主机与虚拟机能相互访问的设置

    1. 桥接网卡 2. 界面名称:802.11n USB Wireless Lan Card 3. 混杂模式:全部允许 4. 接入网线打勾 5. 确定