HDU 1069 Monkey and Banana (DP)
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
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.
Input
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.
Output
Sample Input
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
Sample Output
Case 2: maximum height = 21
Case 3: maximum height = 28
Case 4: maximum height = 342
思路:首先,每个方块的三个维度一共有3*2=6中组合,题目说最多有30个方块,所以数组应该开180以上。思路是DP数组的每个元素存的是以此方块为底的最高能摆的高度,从最顶端那个开始填表,顺便记录下最大值,最后输出最大值即可。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 200 struct x
{
int x;
int y;
int z;
}DP[MAX]; int comp(const void * a,const void * b);
int main(void)
{
int n,max,box,x,y,z,count;
count = ; while(scanf("%d",&n) && n)
{
count ++;
for(int i = ;i < * n;i ++)
{
scanf("%d%d%d",&x,&y,&z);
DP[i].x = x;
DP[i].y = y;
DP[i].z = z; i ++;
DP[i].x = x;
DP[i].y = z;
DP[i].z = y; i ++;
DP[i].x = z;
DP[i].y = y;
DP[i].z = x; i ++;
DP[i].x = z;
DP[i].y = x;
DP[i].z = y; i ++;
DP[i].x = y;
DP[i].y = x;
DP[i].z = z; i ++;
DP[i].x = y;
DP[i].y = z;
DP[i].z = x;
}
qsort(DP, * n,sizeof(struct x),comp); max = DP[ * n - ].z;
for(int i = * n - ;i >= ;i --)
{
box = ;
for(int j = i + ;j < * n - ;j ++)
if(DP[i].x > DP[j].x && DP[i].y > DP[j].y && box < DP[j].z)
box = DP[j].z;
DP[i].z += box;
max = max > DP[i].z ? max : DP[i].z;
}
printf("Case %d: maximum height = %d\n",count,max);
} return ;
} int comp(const void * a,const void * b)
{
return -(((struct x *)a) -> x - ((struct x *)b) -> x);
}
HDU 1069 Monkey and Banana (DP)的更多相关文章
- HDU 1069 Monkey and Banana dp 题解
HDU 1069 Monkey and Banana 纵有疾风起 题目大意 一堆科学家研究猩猩的智商,给他M种长方体,每种N个.然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉. 现在给你M种 ...
- HDU 1069 Monkey and Banana(DP 长方体堆放问题)
Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...
- HDU 1069 Monkey and Banana DP LIS变形题
http://acm.hdu.edu.cn/showproblem.php?pid=1069 意思就是给定n种箱子,每种箱子都有无限个,每种箱子都是有三个参数(x, y, z)来确定. 你可以选任意两 ...
- HDU 1069 Monkey and Banana DP LIS
http://acm.hdu.edu.cn/showproblem.php?pid=1069 题目大意 一群研究员在研究猴子的智商(T T禽兽啊,欺负猴子!!!),他们决定在房顶放一串香蕉,并且给猴子 ...
- HDU 1069 monkey an banana DP LIS
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uDescription 一组研究人员正在 ...
- 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(转换成LIS,做法很值得学习)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS (Java ...
- 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 大意:给出n种箱子的长宽高.每种不限个数.可以堆叠.询问可以达到的最高高度是多少. 要求两个箱子堆叠的时候叠加的面.上面的面的两维长度都严格小于下面的. ...
随机推荐
- iOS7 各种问题解决
1 UITableView 行分割线不到头,短线问题 if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) { ...
- android Notification和NotificationManager的使用
Notification和NotificationManager 1.Broadcast Receiver组件没有提供可视化的界面来显示广播信息.这里我们可以使用Notification和Notifi ...
- 固定分隔符字符串与数组互转及ArrayList与数组(Array)互转
1.字符串转数组 这个相信多数人都会常用,string.split方法,分隔符可以为多个.详细信息参见MSDN string[] actionCfgs = _para.Split(new char[] ...
- CString 转 char*; wstring 转 string
1. CString 转 char* ); CString name; name.Format(_T("bookUC%d.txt"),m_ID); std::wstring _n ...
- js中的null和undefined
大部分编程语言一般有一个表示“无”的值,而js中却有两个,null和undefined.所以查了一些资料,小结在此,以便查阅. js中的变量有两大类,基本的值类型,引用类型.其中值类型分为:Undef ...
- Java中static的用法
static静态,作为修饰符,最初是由c引入,一开始static表示退出一个块后依然存在的局部变量.随后,static表示不能被其他文件访问的全局变量和函数.到了C++和java,static表示属于 ...
- nutch-2.2.1 hadoop-1.2.1 hbase-0.92.1 集群部署
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html 内部邀请码:C8E245J (不写邀请码,没有现金送) 国 ...
- 防火墙没关导致 ORA-12541: TNS: 无监听程序
电脑用着用着突然Oracle就报出下面的错误,按照网上的办法搞了几个小时都没有搞好. Oracle重装了好几次也没用,实在没办法又花了个多小时装了个虚机,结果也是同样的错误. 于是恍然大悟,可能是物理 ...
- SetWindowsHookEx 相关
SetWindowsHookEx function https://msdn.microsoft.com/en-us/library/windows/desktop/ms644990(v=vs.85) ...
- nginx-1.4.4 + tcp_proxy_module手动编译安装
Nginx开源软件默认没有提供TCP协议的负载均衡,下面记录一下我的安装过程: 1. 下载nginx最新稳定版的源码 mkdir /software cd /software yum install ...