POJ2392Space Elevator(贪心+背包)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 9970 | Accepted: 4738 |
Description
Help the cows build the tallest space elevator possible by stacking blocks on top of each other according to the rules.
Input
* 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
Sample Input
3
7 40 3
5 23 8
2 52 6
Sample Output
48
Hint
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(贪心+背包)的更多相关文章
- POJ 2392 Space Elevator(贪心+多重背包)
POJ 2392 Space Elevator(贪心+多重背包) http://poj.org/problem?id=2392 题意: 题意:给定n种积木.每种积木都有一个高度h[i],一个数量num ...
- 【bzoj4922】[Lydsy六月月赛]Karp-de-Chant Number 贪心+背包dp
题目描述 给出 $n$ 个括号序列,从中选出任意个并将它们按照任意顺序连接起来,求以这种方式得到匹配括号序列的最大长度. 输入 第一行包含一个正整数n(1<=n<=300),表示括号序列的 ...
- POJ 2392 Space Elevator(多重背包变形)
Q: 额外添加了最大高度限制, 需要根据 alt 对数据进行预处理么? A: 是的, 需要根据 alt 对数组排序 Description The cows are going to space! T ...
- HDU3466Proud Merchants(贪心&背包)
http://acm.hdu.edu.cn/showproblem.php?pid=3466 题目大意是说n个物品每个物品的花费是p,但是如果你现在的钱少于q就买不了这个物品,每个物品的价值是v,求有 ...
- POJ 2392 Space Elevator 贪心+dp
题目链接: http://poj.org/problem?id=2392 题意: 给你k类方块,每类方块ci个,每类方块的高度为hi,现在要报所有的方块叠在一起,每类方块的任何一个部分都不能出现在ai ...
- Installing Apps Kattis - installingapps (贪心 + 背包)
Installing Apps Kattis - installingapps Sandra recently bought her first smart phone. One of her fri ...
- HDU 5303 Delicious Apples(贪心 + 背包 2015多校啊)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5303 Problem Description There are n apple trees plan ...
- bzoj4922 [Lydsy1706月赛]Karp-de-Chant Number 贪心+背包
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4922 题解 记录每一个串的没有匹配的右括号 \()\) 的数量为 \(a_i\),为匹配的左括 ...
- AT4120-[ARC096D]Sweet Alchemy【贪心,背包】
正题 题目链接:https://www.luogu.com.cn/problem/AT4120 题目大意 给出\(n\)个物品和一个容量\(m\),第\(i\)个物品体积为\(c_i\).除了第一个物 ...
随机推荐
- GridPanel中getSelectionModel
GridPanel中getSelectionModel 更多 2014/5/1 来源:extjs学习浏览量:6783 学习标签: GridPanel extjs 本文导读:Ext.grid.GridP ...
- ab压测&htop工具
1,apache bech 参考: http://www.nginx.cn/110.html http://www.ha97.com/4617.html ===================== y ...
- C# 版本的 计时器类:精确到微秒 秒后保留一位小数 支持年月日时分秒带单位的输出
class TimeCount { // 临时变量,存放当前类能表示的最大年份值 ; /// <summary> /// 获取毫秒能表示的最大年份数 /// </summary> ...
- JavaScript及其异步实现续:Promise让一切更简单
在写这篇文章之前,我参考了以下文章.所以我文中的例子都是精准的,而且有循可依.下面抛出例子的链接: Understanding JQuery.Deferred and Promise Deferred ...
- Photoshop Cc高级设计师培训视频教程(共109节课程)
Photoshop Cc高级设计师培训视频教程(共109节课程) 专业培训Photoshop技能,其他网站收费内容,这里收集了,免费分享给你们哦~ 以下为部分截图: 下载地址: http://fu83 ...
- Caffe学习系列(12):训练和测试自己的图片
学习caffe的目的,不是简单的做几个练习,最终还是要用到自己的实际项目或科研中.因此,本文介绍一下,从自己的原始图片到lmdb数据,再到训练和测试模型的整个流程. 一.准备数据 有条件的同学,可以去 ...
- ubuntu14.04上安装Mysql-5.7.11
先安装好操作系统 在Mysql官网上下载最新版的Ubuntu Linux专用的Mysql.我这里下载的是:mysql-server_5.7.11-1ubuntu14.04_amd64.deb-bu ...
- [CareerCup] 8.7 Chat Server 聊天服务器
8.7 Explain how you would design a chat server. In particular, provide details about the various bac ...
- ASP.NET MVC 5 入门教程 (1) 新建项目
文章来源: Slark.NET-博客园 http://www.cnblogs.com/slark/p/mvc-5-get-started-create-project.html 下一节:ASP.NET ...
- 删除 windows 下 node_modules 过深的目录
本文同步自我的个人博客:http://www.52cik.com/2015/11/13/node-modules-del.html 说到 node 的模块,确实既好用又蛋疼.相信无数人吐槽 node_ ...