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. SharePoint:备份和还原

    注意事项: 1.备份和还原最好都用PowerShell,用时候用管理中心会遇到错误. 2.备份PowerShell要注意数据库服务器名,要与管理中心的数据库服务器一致,用ip可能会报错. Restor ...

  2. HTML中判断手机是否安装某APP,跳转或下载该应用

    有些时候在做前端输出的时候,需要和app的做些对接工作.就是在手机浏览器中下载某app时,能判断该用户是否安装了该应用.如果安装了该应用,就直接打开该应用:如果没有安装该应用,就下载该应用.那么下面就 ...

  3. Design Pattern - Strategy

    Strategy Pattern:     The Strategy Pattern defines a family of algorithms,encapsulates each one,and ...

  4. xampp版本和具体的php,mysql版本的对应

    在国外网上查找到具体的xampp版本与php,mysql版本的对应关系,特此记录.以便需要的人使用.原文链接如下: http://code.stephenmorley.org/articles/xam ...

  5. URL中文参数乱码的一个解决办法

      浏览器对有中文参数的url大部分都用utf-8编码,但我也曾经遇见过用GB2312编码的:如果遇见这样情况,那么接受到的参数就会出现乱码.乱码情况视服务器解码方式,Asp.Net网站一般默认为ut ...

  6. Linux命令学习-useradd和usermod

    1.useradd 创建用户的时候创建家目录 useradd luyun :创建用户luyun,系统会自动创建/home/luyun 目录,此目录便是luyun的家目录. useradd -d /ho ...

  7. c++实现快速排序详细分析

    快速排序坑挺多的,今天有空记录一下自己的实现,并加上详细的注释和举例 #include<iostream> using namespace std; int partion(int num ...

  8. JavaScript 执行环境(执行上下文) 变量对象 作用域链 上下文 块级作用域 私有变量和特权方法

    总结自<高程三>第四章  理解Javascript_12_执行模型浅析   JS的执行环境与作用域  javascript高级程序第三版学习笔记[执行环境.作用域] 在javascript ...

  9. android源码查看所有分支切换分支

    cd .repo/manifests git branch -a repo init -b android-4.1.2_r1 repo sync

  10. mpich2 下运行时出现“由于目标计算机积极拒绝,无法连接”的错误

    进行mpi并行编程时候,win8下使用mpich2时候,安装目录下找到wmpiexec.exe程序打开,填入编写好的.exe程序地址并制定执行的任务数目的想要运行时候,出现错误: unable to  ...