Space Elevator
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 9244   Accepted: 4388

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

题意是要搭梯子,要求的是梯子的最高能达到多少。限制条件一个是每个梯子有自身的限制高度,另外一个是梯子数量。

和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的更多相关文章

  1. poj2392 Space Elevator(多重背包问题)

    Space Elevator   Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8569   Accepted: 4052 ...

  2. poj[2392]space elevator

    Description The cows are going to space! They plan to achieve orbit by building a sort of space elev ...

  3. A - Space Elevator(动态规划专项)

    A - Space Elevator Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  4. POJ 2392 Space Elevator(贪心+多重背包)

    POJ 2392 Space Elevator(贪心+多重背包) http://poj.org/problem?id=2392 题意: 题意:给定n种积木.每种积木都有一个高度h[i],一个数量num ...

  5. poj 2392 Space Elevator(多重背包+先排序)

    Description The cows are going to space! They plan to achieve orbit by building a sort of space elev ...

  6. BZOJ 1739: [Usaco2005 mar]Space Elevator 太空电梯

    题目 1739: [Usaco2005 mar]Space Elevator 太空电梯 Time Limit: 5 Sec  Memory Limit: 64 MB Description The c ...

  7. POJ 2392 Space Elevator(多重背包变形)

    Q: 额外添加了最大高度限制, 需要根据 alt 对数据进行预处理么? A: 是的, 需要根据 alt 对数组排序 Description The cows are going to space! T ...

  8. poj2392 Space Elevator(多重背包)

    http://poj.org/problem?id=2392 题意: 有一群牛要上太空.他们计划建一个太空梯-----用一些石头垒.他们有K种不同类型的石头,每一种石头的高度为h_i,数量为c_i,并 ...

  9. Space Elevator [POJ2392] [DP][优化]

    题目大意 n件物品,第i件hi高,有ci件,最高的一件不能超过ai的高度.问最高能堆多高 输入: 第一行,一个n 接下来每一行,为hi,ai,ci 输出,最高堆多高 样例输入: 37 40 35 23 ...

随机推荐

  1. mac下删除不需要的应用程序

    一般的应用程序删除: 1)可以在 前往--应用程序 中直接删除 2)直接在启动台中按住出现X直接删除. 问题: mac下不出现在应用程序中,启动台中按住也不出现X,也不可以直接拖到废纸篓中删除的应用如 ...

  2. nodejs的C++扩展中实现异步回调

    在nodejs的官方网站中有关于C++扩展的详细说明,其中包含了从"hello world"到对象封装的一系列示例.其中的“callback”节是关于回调函数的,美中不足的是,这个 ...

  3. 在PyCharm中自动添加文件头、时间日期等信息

    初次安装使用PyCharm,在新建.py文件时会发现文件头并没有什么信息,因此,使用模板会比较方便.方法如下: 1.打开PyCharm,选择File--Settings 2.依次选择Editor--- ...

  4. uniGUI之MASK遮罩(22)

    在页面进行后台数据库操作的时候,不想 用户再进行 页面上的 其他操作,这时候就要 将页面 遮罩.例如UniDBGrid有LoadMask属性. 1]使用ScreenMask函数 2]JS调用 3]一个 ...

  5. Python 操作rabbitmq中的confirm模式的错误

    今天使用rabbitmq的confirm模式,书上介绍的是pika版本是0.9.6,但是我用的是别的版本,发现这样的错误 Traceback (most recent call last):  Fil ...

  6. 三 基于Java数组手写循环队列

    Code: package dataStucture2.stackandqueue; /** * 手写循环队列 * * @param <E> */ public class MyLoopQ ...

  7. Linux学习计划中遇到的问题记录

    随时更新 Linux安装到网络联通遇到的问题及解决办法 1.命令区分大小写 2..网络连通 ping本地 地址遇到问题 解决办法: https://blog.csdn.net/qq_42074075/ ...

  8. mathematica练习程序(第一章 Mathematica的基本量)

    虽然过去有用Mathematica解过一些问题,不过对这个语言并没有系统学习过. 所以最近想重新把Mathematica系统的学一遍. 偶然在B站上找到了这样一组教程:https://www.bili ...

  9. SpringCloud学习之Zuul路由转发、拦截和熔断处理(七)

    Spring Cloud Zuul 服务网关是微服务架构中一个不可或缺的部分.通过服务网关统一向外系统提供REST API的过程中,除了具备服务路由.均衡负载功能之外,它还具备了权限控制等功能. Sp ...

  10. ubuntu 怎么更新?ubuntu更新命令及方法

    ubuntu 怎么更新?ubuntu更新命令及方法 安装Ubuntu系统后,第一件事就是更新系统源.由于系统安装的默认源地址在英国,作为Ubuntu的主源,国内连接速度非常慢,所以我们要将它换成就近的 ...