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\).除了第一个物 ...
随机推荐
- KVM虚拟机CPU说明
废话不多说了,下面对kvm虚拟机的CPU说明做一梳理:NUMA技术介绍NUMA是一种解决多CPU共同工作的技术方案,我们先回顾下多CPU共同工作的技术架构历史.多CPU共同工作主要有三种架构,分别是S ...
- RDLC直接打印帮助类
代码 /// <summary> /// 打印帮助类 /// </summary> public class PrintHelper { private int m_curre ...
- 【C#】【Thread】上下文同步域SynchronizationAttribute
上下文同步:使用SynchronizationAttribute为ContextBoundObject对象创建一个简单的自动的同步. 这种同步方式仅用于实例化的方法和域的同步.所有在同一个上下文域的对 ...
- 【转】WCF与Web API 区别(应用场景)
Web api 主要功能: 支持基于Http verb (GET, POST, PUT, DELETE)的CRUD (create, retrieve, update, delete)操作 请求的回 ...
- C语言错误 BUG报错整理
错误一 关键字:间接寻址级别不同 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> ...
- log_bin_trust_function_creators变量解释
在MySQL主从复制机器的master的数据库中创建function,报出如下错误: Error Code: 1418. This function has none of DETERMINISTIC ...
- C++ 排序、查找的应用
// order.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include "string.h" #includ ...
- JQuery学习笔记——JQuery基础
#,JQuery避免名称冲突的方法 var jq = jQuery.noConfilct(); jq.ready( function(){ jq("p").hidden() ...
- Opencv step by step - 视频变换
这次是变换视频内容并且写入新的文件. 代码如下: note:因为代码比较少,前几篇博客的代码都是手打的,并且做了一些修改. #include <cv.h> #include <hig ...
- python为什么会有@classmethod?
今天被问了这么个问题 python为什么要有classmethod? 被问倒了,只能回答:classmethod不需要实例化类,用起来比较方便.这么回答没有什么底细,于是查看了一下python的官方文 ...