HDU 1069 Monkey and Banana(动态规划)
Monkey and Banana
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.
题目大意:给出箱子的长、宽、高,每个箱子有很多种,然后求叠起来的最大高度,上边箱子的长和宽必须小于下边的箱子
代码如下:
# include <iostream>
# include<cstdio>
# include<cstring>
# include<cstdlib>
using namespace std;
struct node
{
int x,y,z;
} s[]; int cmp(const void *a,const void *b)
{
struct node* aa = (node *)a;
struct node* bb = (node *)b;
if(aa->x != bb->x)
return aa->x - bb->x;
else if(aa->y != bb->y)
return aa->y - bb->y;
return aa->z - bb->z;
}
int dp[];
int main()
{
int n,i,j,a,b,c;
int cas = ;
while(scanf("%d",&n)&&n)
{
for(i=; i<n; i++)
{
scanf("%d%d%d",&a,&b,&c);
s[i*].x = a; s[i*].y = b; s[i*].z = c;
s[i*+].x = a; s[i*+].y = c; s[i*+].z = b;
s[i*+].x = b; s[i*+].y = a; s[i*+].z = c;
s[i*+].x = b; s[i*+].y = c; s[i*+].z = a;
s[i*+].x = c; s[i*+].y = a; s[i*+].z = b;
s[i*+].x = c; s[i*+].y = b; s[i*+].z = a;
}
qsort(s,n*,sizeof(s[]),cmp);
for(i=; i<*n; i++)
dp[i] = s[i].z;
int ans = ;
for(i=; i<n*; i++)
{
for(j=; j<i; j++)
{
if(s[i].x > s[j].x && s[i].y > s[j].y && dp[j]+s[i].z > dp[i])
dp[i] = dp[j]+s[i].z ;
}
if(dp[i]>ans)
ans = dp[i];
}
printf("Case %d: maximum height = %d\n",cas++,ans);
}
return ;
}
HDU 1069 Monkey and Banana(动态规划)的更多相关文章
- 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种 ...
- HDU 1069 Monkey and Banana(转换成LIS,做法很值得学习)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS (Java ...
- 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(二维偏序LIS的应用)
---恢复内容开始--- Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- HDU 1069 Monkey and Banana (DP)
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 1069—— Monkey and Banana——————【dp】
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- 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(DP 长方体堆放问题)
Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...
随机推荐
- 【Stage3D学习笔记续】山寨Starling(一):从事件说起
我在GitHub上新开了一个项目:https://github.com/hammerc/hammerc-study-Stage3D 山寨的Starling版本我取名叫做Scorpio2D,以后的笔记中 ...
- .NET MVC4 ApiController拦截器的使用
目前在公司新开发了一个项目,第一次正式使用.NET MVC4来搭建,用拦截器来处理权限验证. 自定义拦截器需继承ActionFilterAttribute类,重写OnActionExecuting和O ...
- SQL Server 2005 盛宴系列 经典教程
SQL Server 2005 盛宴系列 经典教程 [复制链接] 发表于 2007-3-27 14:08 | 来自 51CTO网页 [只看他] 楼主 TECHNET SQL serve ...
- The Sorrows of Young Werther
The Sorrows of Young Werther J.W. von Goethe Thomas Carlyle and R.D. Boylan Edited by Nathen Haskell ...
- PHP中各种Hash算法性能比较
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- Struts2 中的数据传输
1. 如何将参数从界面传递到Action? 你可以把Struts2中的Action看做是Struts1的Action+ActionForm,即只需在Action中定义相关的属性(要有gette ...
- Linux服务器的常用备份方法
系统备份是系统管理工作中十分重要的一个环切,本文详细介绍了各种Linux系统的备份方法,相信对大家的日常管理工作有所帮助. 备份是一项重要的工作,但是很多人没有去做.一旦由于使用不当造成数据丢失,备份 ...
- PHP获取远程图片并调整图像大小
<?php /** * *函数:调整图片尺寸或生成缩略图 *修改:2013-2-15 *返回:True/False *参数: * $Image 需要调整的图片(含路径) * $Dw= ...
- iOS 开发中你是否遇到这些经验问题(一)
前言 小伙伴们在开发中难免会遇到问题, 你是如何解决问题的?不妨也分享给大家!如果此文章其中的任何一条问题对大家有帮助,那么它的存在是有意义的! 反正不管怎样遇到问题就要去解决问题, 在解决问题的同时 ...
- VIM7.3中文手册
INDEX *index.txt* For Vim version 7.3. 最近更新: 2010年7月 VIM 参考手册 by Bram Moolenaar 译者: Willis h ...