POJ2392:Space Elevator
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 9244 | Accepted: 4388 |
Description
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
* 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
题意是要搭梯子,要求的是梯子的最高能达到多少。限制条件一个是每个梯子有自身的限制高度,另外一个是梯子数量。
和POJ1014很像的思路,判断多高是判断每一个可能的高度其DP[]值是否为true,如果为true,记录其最大值即可。
我那种代码最后的内存会很大,没必要在sum上申请二维数组,一维的就足够了,每一次清零就好。
代码:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std; int dp[40002];
int sum[40002][410];//数组一开始开小了
struct Node{
int h;
int cant;
int num;
}node[500]; bool cmp(Node no1,Node no2)
{
return no1.cant < no2.cant;
} int main()
{
int count;
int i; cin>>count;
for(i=1;i<=count;i++)
{
cin>>node[i].h>>node[i].cant>>node[i].num;
}
sort(node+1,node+1+count,cmp); memset(sum,0,sizeof(sum));
memset(dp,0,sizeof(dp));
dp[0]=1;
int j,ans=0;
for(i=1;i<=count;i++)
{
for(j=node[i].h;j<=node[i].cant;j++)
{
if(!dp[j]&&dp[j-node[i].h]&&sum[j-node[i].h][i]<node[i].num)
{
sum[j][i] = sum[j-node[i].h][i]+1;
dp[j]=1;
if(j>ans)
ans=j;
}
}
}
cout<<ans<<endl; return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
POJ2392:Space Elevator的更多相关文章
- poj2392 Space Elevator(多重背包问题)
Space Elevator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8569 Accepted: 4052 ...
- poj[2392]space elevator
Description The cows are going to space! They plan to achieve orbit by building a sort of space elev ...
- A - Space Elevator(动态规划专项)
A - Space Elevator Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- POJ 2392 Space Elevator(贪心+多重背包)
POJ 2392 Space Elevator(贪心+多重背包) http://poj.org/problem?id=2392 题意: 题意:给定n种积木.每种积木都有一个高度h[i],一个数量num ...
- poj 2392 Space Elevator(多重背包+先排序)
Description The cows are going to space! They plan to achieve orbit by building a sort of space elev ...
- BZOJ 1739: [Usaco2005 mar]Space Elevator 太空电梯
题目 1739: [Usaco2005 mar]Space Elevator 太空电梯 Time Limit: 5 Sec Memory Limit: 64 MB Description The c ...
- POJ 2392 Space Elevator(多重背包变形)
Q: 额外添加了最大高度限制, 需要根据 alt 对数据进行预处理么? A: 是的, 需要根据 alt 对数组排序 Description The cows are going to space! T ...
- poj2392 Space Elevator(多重背包)
http://poj.org/problem?id=2392 题意: 有一群牛要上太空.他们计划建一个太空梯-----用一些石头垒.他们有K种不同类型的石头,每一种石头的高度为h_i,数量为c_i,并 ...
- Space Elevator [POJ2392] [DP][优化]
题目大意 n件物品,第i件hi高,有ci件,最高的一件不能超过ai的高度.问最高能堆多高 输入: 第一行,一个n 接下来每一行,为hi,ai,ci 输出,最高堆多高 样例输入: 37 40 35 23 ...
随机推荐
- shell脚本基础及重定向!
重定向: 补充:/dev/null(名叫黑洞)就是把输出的文件混合重定向到黑洞从而不显示在屏幕 yum -y install http &> /dev/null 重定向输入: 重定向输出 ...
- 分支预测(branch prediction)
记录一个在StackOverflow上看到一个十分有趣的问题:问题. 高票答案的优化方法: 首先找到罪魁祸首: if (data[c] >= 128) sum += data[c]; 优化方案使 ...
- js通过cookie对两个没有关系的jsp页面进行传值
//Cookie取值 function readCookie (name) { var cookieValue = ""; var search = name + "=& ...
- linux系统登陆过程
一.物理直连登陆过程 初始化进程init 会根据直接连接的字符终端设备,打开getty程序,并关联在字符终端设备上tty1/2/3/4/5/6/7....上,在不同的终端设备上提示用户输入信息,等待终 ...
- [转]网络协议-redis协议
Redis 通信协议(protocol) 本文档翻译自: http://redis.io/topics/protocol . Redis 协议在以下三个目标之间进行折中: 易于实现 可以高效地被计算机 ...
- Linux命令(1)
cd <directory> Short for "change directory". The shorthand name for the current dire ...
- Day1-Luogu-1631
题目描述 有两个长度都是N的序列A和B,在A和B中各取一个数相加可以得到N^2N2个和,求这N^2N2个和中最小的N个. 输入输出格式 输入格式: 第一行一个正整数N: 第二行N个整数A_iAi, ...
- 关于fpga的后仿真重要性
也许你天天做些fpga,写完代码就直接编译成功,锁定引脚后,马上使用signaltaII软件. 也许你一天,你发现signaltapII看信号的痛苦,一个源代码文件修改一点,要花个20分钟编译一次. ...
- java对象转换String类型的三种方法
在很多情况下我们都需要将一个对象转换为String类型.一般来说有三种方法可以实现:Object.toString().(String)Object.String.valueOf(Object).下面 ...
- Java系列之:看似简单的问题 静态方法和实例化方法的区别
(2011-12-06 15:28:26) 转载▼ 标签: 杂谈 分类: study 今天看书时一直没真正弄明白静态方法和实例方法的区别,就在网上搜索,找到一篇很好的文章,和大家分享一下: 这是一个经 ...