A - Space Elevator(动态规划专项)
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Description
Help the cows build the tallest space elevator possible by stacking blocks on top of each other according to the rules.
Input
* 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
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(动态规划专项)的更多相关文章
- poj[2392]space elevator
Description The cows are going to space! They plan to achieve orbit by building a sort of space elev ...
- poj 2392 Space Elevator(多重背包+先排序)
Description The cows are going to space! They plan to achieve orbit by building a sort of space elev ...
- BZOJ 1739: [Usaco2005 mar]Space Elevator 太空电梯
题目 1739: [Usaco2005 mar]Space Elevator 太空电梯 Time Limit: 5 Sec Memory Limit: 64 MB Description The c ...
- POJ 2392 Space Elevator(多重背包变形)
Q: 额外添加了最大高度限制, 需要根据 alt 对数据进行预处理么? A: 是的, 需要根据 alt 对数组排序 Description The cows are going to space! T ...
- poj2392 Space Elevator(多重背包问题)
Space Elevator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8569 Accepted: 4052 ...
- POJ 2392 Space Elevator(贪心+多重背包)
POJ 2392 Space Elevator(贪心+多重背包) http://poj.org/problem?id=2392 题意: 题意:给定n种积木.每种积木都有一个高度h[i],一个数量num ...
- POJ2392:Space Elevator
Space Elevator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9244 Accepted: 4388 De ...
- POJ 2392 Space Elevator DP
该题与POJ 1742的思路基本一致:http://www.cnblogs.com/sevenun/p/5442279.html(多重背包) 题意:给你n个电梯,第i个电梯高h[i],数量有c[i]个 ...
- DP:Space Elevator(POJ 2392)
太空电梯 题目大意:一群牛想造电梯到太空,电梯都是由一个一个块组成的,每一种块不能超过这个类型的高度,且每一种块都有各自的高度,有固定数量,问最高能造多高. 这题就是1742的翻版,对ai排个序就可以 ...
随机推荐
- web service client端调用服务器接口
打开项目的web service client 其中wsdl URL http://www.51testing.com/html/55/67755-848510.html 去这里面查找一些公开的 ...
- webAPI---发布(IIS)--发布遇到问题(500.19,500.21,404.8,404.3)
WebAPI的内容部分直接转自官方文档,英语水平有限,不做翻译, 发布网站在本文的后半部分 HTTP is not just for serving up web pages. It is also ...
- HihoCoder
#1043 : 完全背包 20160516 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 且说之前的故事里,小Hi和小Ho费劲心思终于拿到了茫茫多的奖券!而现在,终于到 ...
- 按键精灵*ff
Function gethttp(URL) Set objXML=CreateObject("Microsoft.XMLHTTP") objXML.Open "Get&q ...
- 【转】Jmeter(二)-使用代理录制脚本
Jmeter脚本是以JMX格式为主 Jmeter也是支持录制的,支持第三方录制方式和代理录制方式. 1.第三方录制主要是通过badboy来录制,录制后另存为jmx格式即可. 2.Jmeter也有自己的 ...
- Oracle SQL自带函数整理
数字函数 abs(n):用于返回数字n的绝对值 ceil(n):返回大于等于数字n的最小整数 floor(n):返回小于等于数字n的最大整数 mod(m,n):返回m/n数字相除后的余数,如果n=0, ...
- 用 yo aspnet 生成.net项目
yo指的是Yeoman 官网:http://yeoman.io/ 因为安装yo需要nmp 因此 要先到node官网下载node并按装 安装之后就可以下一步了 $ npm install -g yo g ...
- 客户端socket调用
import java.net.Socket; import java.io.*; import java.util.Scanner; import java.util.regex.Pattern; ...
- 阿里云 CentOS7.2 配置FTP+Node.js环境
本人小白,写下这篇博客意在记录踩过的坑,大神请绕道~ 准备工作 安装自己喜欢的连接软件(一般是putty或者xshell),本人选择的是xshell,软件如图 : 通过软件中的ssh连接连接上已经购买 ...
- Redis6-sorted set 的介绍
Sort Set排序集合类型(1)介绍和set一样sorted set也是string类型元素的集合,不同的是每个元素都会关联一个权.通过权值可以有序的获取集合中的元素该Sort Set类型适合场合: ...