Monkey and Banana(HDU 1069 动态规划)
Monkey and Banana
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10987 Accepted Submission(s): 5732
The researchers have n types of blocks, and an unlimited supply of blocks of each type. Each type-i block was a rectangular solid with linear dimensions (xi, yi, zi). A block could be reoriented so that any two of its three dimensions determined the dimensions of the base and the other dimension was the height.
They want to make sure that the tallest tower possible by stacking blocks can reach the roof. The problem is that, in building a tower, one block could only be placed on top of another block as long as the two base dimensions of the upper block were both strictly smaller than the corresponding base dimensions of the lower block because there has to be some space for the monkey to step on. This meant, for example, that blocks oriented to have equal-sized bases couldn't be stacked.
Your job is to write a program that determines the height of the tallest tower the monkey can build with a given set of blocks.
representing the number of different blocks in the following data set. The maximum value for n is 30.
Each of the next n lines contains three integers representing the values xi, yi and zi.
Input is terminated by a value of zero (0) for n.
10 20 30
2
6 8 10
5 5 5
7
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
5
31 41 59
26 53 58
97 93 23
84 62 64
33 83 27
0
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct blo
{
int x,y,z;
}a[];
int dp[];
bool cmp(blo u,blo v)
{
int t=u.x*u.y-v.x*v.y;
if(t==)
return u.z<=v.z;
else if(t<)
return ;
else
return ;
}
int main()
{
int i,j;
int n;
int t=;
freopen("in.txt","r",stdin);
while(scanf("%d",&n)&&n)
{
memset(dp,,sizeof(dp));
for(i=;i<=*n;i+=)
{
scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].z);
if(a[i].x>a[i].y)
{
int temp=a[i].x;
a[i].x=a[i].y;
a[i].y=temp;
}
a[i+].x=min(a[i].y,a[i].z),a[i+].y=max(a[i].y,a[i].z),a[i+].z=a[i].x;
a[i+].x=min(a[i].x,a[i].z),a[i+].y=max(a[i].x,a[i].z),a[i+].z=a[i].y;
}
sort(a+,a+*n+,cmp);
for(i=;i<=*n;i++)
{
dp[i]=a[i].z;
for(j=;j<i;j++)
{
if(a[j].x<a[i].x&&a[j].y<a[i].y&&(dp[j]+a[i].z)>dp[i])
dp[i]=dp[j]+a[i].z;
}
}
int m=;
for(i=;i<=*n;i++)
m=max(m,dp[i]);
printf("Case %d: maximum height = %d\n",t++,m);
}
}
Monkey and Banana(HDU 1069 动态规划)的更多相关文章
- (最大上升子序列)Monkey and Banana -- hdu -- 1069
http://acm.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit:1000MS Memory L ...
- (动态规划 最长有序子序列)Monkey and Banana --HDU --1069
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1069 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- Monkey and Banana HDU - 1069 有点像背包,又像最长上升序列
#include<iostream> #include<algorithm> #include<cstring> #include<vector> us ...
- Day9 - F - Monkey and Banana HDU - 1069
一组研究人员正在设计一项实验,以测试猴子的智商.他们将挂香蕉在建筑物的屋顶,同时,提供一些砖块给这些猴子.如果猴子足够聪明,它应当能够通过合理的放置一些砖块建立一个塔,并爬上去吃他们最喜欢的香蕉. ...
- Monkey and Banana 题解(动态规划)
Monkey and Banana 简单的动态规划 1.注: 本人第一篇博客,有啥不足还请多多包涵,有好的建议请指出.你以为有人读你博客,还给你提意见. 2.原题 Background: A grou ...
- HDU 1069 Monkey and Banana(动态规划)
Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...
- HDU 1069 Monkey and Banana (动态规划、上升子序列最大和)
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1069 Monkey and Banana / ZOJ 1093 Monkey and Banana (最长路径)
HDU 1069 Monkey and Banana / ZOJ 1093 Monkey and Banana (最长路径) Description A group of researchers ar ...
- HDU 1069 Monkey and Banana dp 题解
HDU 1069 Monkey and Banana 纵有疾风起 题目大意 一堆科学家研究猩猩的智商,给他M种长方体,每种N个.然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉. 现在给你M种 ...
随机推荐
- 二维指针*(void **)的研究(uC/OS-II案例) 《转载》
uC/OS-II内存管理函数内最难理解的部分就是二维指针,本文以图文并茂的方式对二维指针进行了详细分析与讲解.看完本文,相信对C里面指针的概念又会有进一步的认识. 一.OSMemCreate( ) 函 ...
- 一个ajax的后台controller
@RequestMapping("/api/merBrand") @ResponseBody public ResultBrand merBrand(HttpServletRequ ...
- MongoDB再实测
不用安装,直接解压.. 这些都不是最主要的,,,倒是TOMCAT和NGINX还需要更深入的了解... http://jingyan.baidu.com/article/acf728fd3d398bf8 ...
- Codeforces 276D Little Girl and Maximum XOR
题意:给范围l,r选两个数亦或最大是多少. 思路:找到第一个l和r二进制下不相同的位置i,然后答案就是2^(i+1)-1,因为一个取0一个取1之后,后面的位置全部选1和全部选0,就是这样:011111 ...
- win10系统加载ahci驱动的操作方案(Win10之家)
win10系统使用的过程中很多用户会想要加载ahci驱动,但是大部分用户根本不知道怎么操作加载ahci驱动,这样的话很多用户会遇到一些问题,那如果使用的过程中想要加载ahci驱动的话我们应该怎么操作呢 ...
- HTTP 504 错误
5xx(服务器错误)这些状态代码表示,服务器在尝试处理请求时发生内部错误.这些错误可能是服务器本身的错误,而不是请求出错. 504(网关超时) 服务器作为网关或代理,未及时从上游服务器接收请求. 50 ...
- logstash tomcat catalina.out 告警
<pre name="code" class="html">[elk@dr-mysql01 tomcat]$ cat logstash_tomcat ...
- wikioi1082【线段树练习 3 】
题目描述 Description 给你N个数,有两种操作: 1:给区间[a,b]的所有数增加X 2:询问区间[a,b]的数的和. 输入描述 Input Description 第一行一个正整数n,接下 ...
- 学完 JAVA SE后学什么 。。。
我觉得学习j2ee一定要循序渐进,千万不要太急了.把java基础打牢一点,再牢一点.各位,你们在后面学习什么 struts,hibernate,spring,ajax..都很轻松. 第一个阶段(jav ...
- WebGIS在行业中应用的演变
结合我本身的项目及WebGIS在公检法行业中的应用,对此作了一个演变过程的总结: 第一阶段:GIS基本功能的应用:Data Show(数据展示):Search(搜索):Search b ...