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 ...
随机推荐
- 动态设置WX滚动条的高度(非常重要)
wxml: <scroll-view class="scroll" scroll-y="true" style="height:{{client ...
- Linux 长时间操作设置不断开
1.第一次尝试失败 修改/etc/ssh/sshd_config文件, 找到 ClientAliveInterval 0 ClientAliveCountMax 3 并将注释符号("#&qu ...
- 「luogu2617」Dynamic Rankings
「luogu2617」Dynamic Rankings 传送门 树套树直接上树状数组套主席树,常数很大就是了. 树套树参考代码: /*-------------------------------- ...
- JavaScript图形实例:正弦曲线
正弦曲线的坐标方程为: Y=A*SIN(X) (A为振幅) 1.正弦曲线 在弧度为0~4π的正弦曲线上取360个点,将这些点用线连接起来,可以绘制出正弦曲线.编写如下的HTML代码. <! ...
- C#往TextBox的方法AppendText加入的内容里插入换行符----转载
C# TextBox换行[huan hang]时你往往会想到直接付给一个含有换行[huan hang]符"\n"的字符[zi fu]串[zi fu chuan]给Text属性[sh ...
- Liunx 如何查看80端口被哪个程序所占用
场景:启服务时一直报80端口被占用 解决方: 1.首先查看下 80 端口的使用情况 netstat -anp|grep 80 查看80端口被被占用的PID 2.根据这个PID 来查看被哪个程序在使用 ...
- 每日算法 - day 15
每日算法 those times when you get up early and you work hard; those times when you stay up late and you ...
- DICOM设备Raw Data与重建
DICOM设备Raw Data与重建 现在的医疗影像设备基本都已DICOM为标准.但现在许多医院的技术人员都以为只要支持DICOM就一切OK,其实不然.DICOM中有Storage.Prin ...
- lnmp1.5下安装mongodb
一.安装mongodb .下载MongoDB 2.6.0二进制发行版 $ curl -O http://downloads.mongodb.org/linux/mongodb-linux-x86_64 ...
- 想要转战CSDN了!!
CSDN博客地址: https://blog.csdn.net/weixin_41559364