A - Space Elevator

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Submit Status

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

题意:有一群牛要上太空,他们计划建一个太空梯(用一些石头垒),他们有k种不同类型的石头,每一种石头的高度为h,数量为c,由于会受到太空辐射,每一种石头不能超过这种石头的最大建造高度a,求解利用这些石头所能修建的太空梯的最高的高度.
 多重背包问题,与一般的多重背包问题所不同的知识多了一个限制条件就是某些"物品"叠加起来的"高度"不能超过一个值,于是我们可以对他们的最高可能达到高度进行排序,然后就是一般的多重背包问题了 思路:
首先是录入数据,这一点比较简单,但是最好用scanf,因为它比cin快;
录入之后对各个数据按照最大的使用高度进行排序,就会转化成一个一般的多重背包为题,一开始我是用原始的多重背包做的麻烦并且也没有A了,最后看了一下题解,是因为每种块的使用个数的计算处理不当;
 #include <iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<memory.h>
using namespace std;
int a[];
struct node
{
int h;
int max;
int shu;
};
node num[];
int dp[];
bool cmp(node a,node b)
{
return a.max<b.max;
}
int main()
{
// freopen("1.txt","r",stdin);
int i,j,k;
int m;
memset(dp,,sizeof(dp));
dp[]=;
int sum[];
cin>>k;
for(i=;i<k;i++)
{
scanf("%d%d%d",&num[i].h,&num[i].max,&num[i].shu);
}
sort(num,num+k,cmp);
m=num[k-].max;
int ans=;
for(i=;i<k;i++)
{
memset(sum,,sizeof(sum));
for(j=num[i].h;j<=num[i].max;j++)
{
if(!dp[j]&&dp[j-num[i].h]&&sum[j-num[i].h]<num[i].shu)
{
dp[j]=;
sum[j]=sum[j-num[i].h]+;//提柜条件,表示到达j高度已经用的砖的个数
if(ans<j)
ans=j;
}
}
}
cout<<ans<<endl;
return ;
}

A - Space Elevator(动态规划专项)的更多相关文章

  1. poj[2392]space elevator

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

  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. BZOJ 1739: [Usaco2005 mar]Space Elevator 太空电梯

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

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

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

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

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

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

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

  7. POJ2392:Space Elevator

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

  8. POJ 2392 Space Elevator DP

    该题与POJ 1742的思路基本一致:http://www.cnblogs.com/sevenun/p/5442279.html(多重背包) 题意:给你n个电梯,第i个电梯高h[i],数量有c[i]个 ...

  9. DP:Space Elevator(POJ 2392)

    太空电梯 题目大意:一群牛想造电梯到太空,电梯都是由一个一个块组成的,每一种块不能超过这个类型的高度,且每一种块都有各自的高度,有固定数量,问最高能造多高. 这题就是1742的翻版,对ai排个序就可以 ...

随机推荐

  1. 职责链模式(Chain of Responsibility)(对象行为型)

    1.概述 你去政府部门求人办事过吗?有时候你会遇到过官员踢球推责,你的问题在我这里能解决就解决,不能解决就推卸给另外个一个部门(对象).至于到底谁来解决这个问题呢?政府部门就是为了可以避免屁民的请求与 ...

  2. 修改LibreOffice Draw中定义的样式名称

    目前我使用的是LibreOffice 4.2.4.2.经过以往的测试和使用经验,这是诸多版本中较为稳定和bug相对较少的.今天无意中发现该版本的LibreOffice Draw存在一个问题:样式名称修 ...

  3. 通过一个表的id同时查询多个表的数据

    'select c.字段名,x.字段名 as 改为新的显示名,x.字段名 from 表名1 b,表名2 c,表名3 x where b.字段id=' . $id . ' and b.`字段id`=c. ...

  4. 面试题-Java基础-垃圾回收

    1.Java中垃圾回收有什么目的?什么时候进行垃圾回收? 垃圾回收的目的是识别并且丢弃应用不再使用的对象来释放和重用资源. 2.System.gc()和Runtime.gc()会做什么事情? 这两个方 ...

  5. ios GCD的使用及封装

    实现代码: CGDHelper /* * Grand Central Dispatch (GCD)是Apple开发的一个多核编程的解决方法. * 系统要求:iOS4.0以上. */ #import & ...

  6. centos 日常操作指令

    ls  ls -li 查看当前目录下所有目录 ls -al 查看当前目录下所有目录包括隐藏文件 CD  cd 目录 跳转指定目录 cd ..返回上级目录 cd / 返回根目录 VI  1. 使用vi进 ...

  7. CSS绑定

    css绑定会对元素的CSS类进行操作.在某些情况下这将非常有用,例如:当数值是负的时将其高亮显示. (注:如果如果不想直接更改CSS类,而是只要改其中一个样式,则需要使用style绑定) 示例:使用静 ...

  8. linux内存管理(repost)

    一 为什么需要使用虚拟内存 大家都知道,进程需要使用的代码和数据都放在内存中,比放在外存中要快很多.问题是内存空间太小了,不能满足进程的需求,而且现在都是多进程,情况更加糟糕.所以提出了虚拟内存,使得 ...

  9. php分类

    <?php /* * PHP分页类 * @package Page * @Created 2013-03-27 * @Modify 2013-03-27 * @link http://www.6 ...

  10. hdu1016

    #include <stdio.h>#include <string.h> int prime[38]={0,0,1,1,0,1,0,1,0,0,0,1,0,1,0,0,0,1 ...