Monkey and Banana

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13837    Accepted Submission(s): 7282

Problem Description

A group of researchers are designing an experiment to test the IQ of a monkey. They will hang a banana at the roof of a building, and at the mean time, provide the monkey with some blocks. If the monkey is clever enough, it shall be able to reach the banana by placing one block on the top another to build a tower and climb up to get its favorite food.

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

The input file will contain one or more test cases. The first line of each test case contains an integer n,
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

For each test case, print one line containing the case number (they are numbered sequentially starting from 1) and the height of the tallest possible tower in the format "Case case: maximum height = height".
 

Sample Input

1
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 1: maximum height = 40
Case 2: maximum height = 21
Case 3: maximum height = 28
Case 4: maximum height = 342
 

Source

 
 //2017-03-14
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; const int N = ;
int n, dp[N*];//DAG模型,dp[i]表示从第i个箱子出发能够走的最大值
struct node
{
int x, y, z;
void setNode(int a, int b, int c){
this->x = a;
this->y = b;
this->z = c;
}
}box[N*]; int dfs(int i)
{
int& ans = dp[i];
if(ans)return ans;//记忆化搜索
ans = ;
for(int j = ; j < n*; j++)
{
if(box[i].x > box[j].x && box[i].y > box[j].y)
{
ans = max(ans, dfs(j));
}
}
ans += box[i].z;
return ans;
} int main()
{
int a, b, c, kase = ;
while(cin>>n && n)
{
int cnt = ;
memset(dp, , sizeof(dp));
for(int i = ; i < n; i++)
{
cin>>a>>b>>c;
box[cnt++].setNode(a, b, c);
box[cnt++].setNode(a, c, b);
box[cnt++].setNode(b, a, c);
box[cnt++].setNode(b, c, a);
box[cnt++].setNode(c, a, b);
box[cnt++].setNode(c, b, a);
}
for(int i = ; i < n*; i++)
dfs(i);
int ans = ;
for(int i = ; i < n*; i++)
if(dp[i] > ans)ans = dp[i];
cout<<"Case "<<++kase<<": maximum height = "<<ans<<endl;
} return ;
}

HDU1069(KB12-C)的更多相关文章

  1. HDU1069 Monkey and Banana

    HDU1069 Monkey and Banana 题目大意 给定 n 种盒子, 每种盒子无限多个, 需要叠起来, 在上面的盒子的长和宽必须严格小于下面盒子的长和宽, 求最高的高度. 思路 对于每个方 ...

  2. HDU-1069 Monkey and Banana DAG上的动态规划

    题目链接:https://cn.vjudge.net/problem/HDU-1069 题意 给出n种箱子的长宽高 现要搭出最高的箱子塔,使每个箱子的长宽严格小于底下的箱子的长宽,每种箱子数量不限 问 ...

  3. ACM-经典DP之Monkey and Banana——hdu1069

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...

  4. HDU1069:Monkey and Banana(DP+贪心)

    Problem Description A group of researchers are designing an experiment to test the IQ of a monkey. T ...

  5. hdu1069(dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 分析: 每种石头有六种方法,那么等效为:有6*n种石头. 根据x和y排序(要保证相应的x.y总有 ...

  6. HDU1069 最长上升子序列

    emm....矩形嵌套 还记得吗....就是它... 直接贴代码了.... import java.util.ArrayList; import java.util.Arrays; import ja ...

  7. hdu1069线性dp

    /* dp[i]:取第i个方块时最多可以累多高 */ #include<bits/stdc++.h> using namespace std; struct node{ int x,y,z ...

  8. HDU-1069.MonkeyandBanana(LIS)

    本题大意:给出n个长方体,每种长方体不限量,让你求出如何摆放长方体使得最后得到的总高最大,摆设要求为,底层的长严格大于下层的长,底层的宽严格大于下层的宽. 本题思路:一开始没有啥思路...首先应该想到 ...

  9. HDU1069(还是dp基础)

    今天不想说太多废话-由于等下要写自己主动提交机. 不知道能不能成功呢? 题目的意思就是,一个猴子,在叠砖头 ...以下的要严格大于上面的.求叠起来最高能到多少- n非常少,n^2算法毫无压力-话说dp ...

随机推荐

  1. [学习笔记]K-D Tree

    以前其实学过的但是不会拍扁重构--所以这几天学了一下 \(K-D\ Tree\) 的正确打开姿势. \(K\) 维 \(K-D\ Tree\) 的单次操作最坏时间复杂度为 \(O(k\times n^ ...

  2. Python大法之告别脚本小子系列—各类URL采集器编写

    本文作者:i春秋签约作家——阿甫哥哥 系列文章专辑:https://bbs.ichunqiu.com/forum.php?mod=collection&action=view&ctid ...

  3. 全世界最顶级黑客同时沸腾在DEF CON 25,是怎样一种体验?

    2017,我在这里!圆你黑客梦!!   被称为黑客“世界杯”与“奥斯卡”的美国黑帽技术大会Black Hat和世界黑客大会DEF CON 是众多黑客心中最神圣的梦!   有位小表弟告诉我说:Black ...

  4. karma 启动提示PhantomJS not found on PATH

    Karma 介绍:是由AngularJS团队开发的测试执行过程管理实用工具,帮助开发人员在不同的浏览器中执行测试. 一般搭配PhantomJS作为浏览器启动器.PhantomJS是一个非主流的Webk ...

  5. 3DMax——基础

    1.首次打开3DMAX设置单位: 自定义→单位设置→①系统单位设置→1单位=1.0毫米:②公制→毫米 注:室内单位为毫米,室外单位为米 2.从CAD导出可以导入到3DMAX的文件: 选中要导出的部分→ ...

  6. MVC3学习:利用mvc3+ajax实现删除记录

    首先根据模板生成list视图,上面就会有一个delete的链接,但是模板自带的这种删除,需要另外再打开一个删除页,再进行删除.我们可以利用ajax来改写,实现在当前页删除. 在视图上面,将原来的 @H ...

  7. flume常用组件

    Flume组件 1.   Source NetCat Source:绑定的端口(tcp.udp),将流经端口的每一个文本行数据作为Event输入: type:source的类型,必须是netcat. ...

  8. c++处理类型与自定义数据结构

    1.typedef 类型别名 有时我们在阅读c++程序时,发现一些未见过的类型,这实际上就是typedef导致的,使用很简单,如下: typedef int wayne; wayne a = , b ...

  9. 在Android中调用KSOAP2库访问webservice服务出现的服务端返回AnyType{}

    最近在做毕业设计的时候,涉及到了安卓端访问web service服务端数据库,并返回一个值,当我把web service测试通过后,想写一个简单的安卓测试程序,来实现服务端数据库访问,通过web se ...

  10. PLSQL Developer概念学习系列之登录连接Oracle时出现(没有登录) -PL / SQL Developer:ORA - 12541: TNS :无建听程序的错误解决办法(图文详解)

    不多说,直接上干货! 前期博客 PLSQL Developer概念学习系列之如何正确登录连接上Oracle(图文详解)   如用scott.scott_password进行登录,orcl是全局数据库 ...