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. uniapp - 手机调试 ( vivo )

    打开开发者选项,打开USB设置,把默认USB选项改成MIDI模式,就可以检测到手机

  2. awk及sum求和!

    awk 也是一个强大的编辑工具,它比 sed 的功能更加强大,可以在无交互的情况下实现相当复杂的文本操作. 1.awk 的语法 awk [选项] ' print $1' 文件名 选项 -F指定分隔符 ...

  3. HIHOcoder编程总结

    [Offer收割]编程练习赛44 对于第一题题目1 : 扫雷游戏,首先要想清楚思路,虽然是暴力算法,但是这八个方向要自己把坐标写正确,不要慌乱,自己写的时候就写错了一个,第二个就是判断的时候,j + ...

  4. Python 基础之import导包

    首先需要将import内容建立一个大概如下层级的包: 以黑色框为第一级,蓝色框为第二级,棕色框为第三级,红色框为第四级 一.import 引入初识 首先在module.py写入代码如下: xboy = ...

  5. 【剑指Offer面试编程题】题目1510:替换空格--九度OJ

    题目描述: 请实现一个函数,将一个字符串中的空格替换成"%20".例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy. 输入: 每个 ...

  6. Ubuntu的妥协将支持精选的32位应用

    据外媒Tom's hardware,Ubuntu开发人员Canonical在早先的时候宣布Ubuntu 19.10将不再更新32位软件包和应用程序,引来了诸多应用开发者的不满.现在,Ubuntu方面宣 ...

  7. XML中报错

    错误描述如下: Multiple annotations found at this line: - cvc-complex-type.2.4.a: Invalid content was found ...

  8. 30 整数中1出现的次数(从1到n整数中1出现的次数)这题很难要多看*

    题目描述 求出1~13的整数中1出现的次数,并算出100~1300的整数中1出现的次数?为此他特别数了一下1~13中包含1的数字有1.10.11.12.13因此共出现6次,但是对于后面问题他就没辙了. ...

  9. 解决maven项目创建过慢的问题,一直resolving dependencies...

    ##方法一: 1.在创建项目时设置其Properties (我大多在创建项目时 就解决这个问题) 创建项目的时候,在Properties属性面板中添加一项:archetypeCatalog = int ...

  10. C# 创建Windows Service(Windows服务)程序

    本文介绍了如何用C#创建.安装.启动.监控.卸载简单的Windows Service 的内容步骤和注意事项. 一.创建一个Windows Service 1)创建Windows Service项目 2 ...