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. linux 部署java 项目命令

    1:服务器部署路径:/home/tomcat/tomcat/webapps  (用FTP工具链接服务器把包上传到此目录) 2:进入项目文件夹 cd /home/tomcat/tomcat/webapp ...

  2. Qtxlsx的使用

    上一遍讲述了基于Qt5.9.8下编译Xtxlsx,本遍讲述基于Qt5.9.8下使用Qtxlsx 1.打开Qt Creator 4.8.2(Enterprise),创建工程,选择版本 2.在pro文件中 ...

  3. axios发送post请求[body-parser]--['Content-type': 'application/x-www-form-urlencoded']

    const express = require('express') const axios = require('axios') const bodyParser = require('body-p ...

  4. express框架开发接口部署线上环境PM2

    1.PM2介绍 PM2是一个线上环境下,用于启动nodejs进程守护的工具,用来保证服务的稳定及分摊服务器进程和压力. 2.下载安装 npm install pm2 -g  => pm2 --v ...

  5. 一文解读CAP (转)

    分布式系统(distributed system)正变得越来越重要,大型网站几乎都是分布式的. 分布式系统的最大难点,就是各个节点的状态如何同步.CAP 定理是这方面的基本定理,也是理解分布式系统的起 ...

  6. C#Winfrom实现Skyline画直线功能

    C#Winfrom实现Skyline画直线功能 前言: 这里记录了我在学习Skyline二次开发中所遇到的问题,适合刚接触Skyline二次开发的同学查看使用,从逻辑到代码逐一详解,但是还是重在理解, ...

  7. springMVC List对象转换为json列表对象

    @ResponseBody @RequestMapping("xxx.do") public List<POJO> getList(){ return List< ...

  8. 图片IO域 旋转画面的组态 图片是4个静止的风扇 PLC的MW6为风扇指针..

    图片IO域 旋转画面的组态 图片是4个静止的风扇 PLC的MW6为风扇指针.. Plc在循环中断组织块 OB35 中 将MW6 每100ms 加1 加到4 清0 图片[MW6] MW6 是图片指针 对 ...

  9. 【C++】【STL】【map】基础知识干货

    1.map简介 map是一种关联式容器,主要用于对数据一对一的映射. 2.map的构造 (1)头文件:#include<map> (2)定义:map<第一关键字,第二关键字> ...

  10. docker学习笔记-05:Docker安装mysql和redis

    一.安装mysql 1.docker hub 上查找mysql镜像 docker search mysql 2.从docker hub (使用阿里云加速器)拉取mysql镜像到本地标签为5.6 doc ...