Monkey and Banana

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Appoint description: 
prayerhgq  (2015-08-04)
System Crawler  (2015-09-05)

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
 
 
 #include <iostream>
#include <cstdio>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <climits>
using namespace std; const int SIZE = ;
int COUNT,DP[SIZE];
struct Node
{
int x,y,z;
}S[SIZE]; void ex(const Node &);
bool comp(const Node & r_1,const Node & r_2);
int main(void)
{
int n,count = ; while(scanf("%d",&n) != EOF && n)
{
count ++;
COUNT = ;
fill(DP,DP + SIZE,);
for(int i = ;i < n;i ++)
{
scanf("%d%d%d",&S[COUNT].x,&S[COUNT].y,&S[COUNT].z);
ex(S[COUNT]);
}
sort(S,S + COUNT,comp); int ans = -;
for(int i = ;i < COUNT;i ++)
{
DP[i] = S[i].z;
int max = -;
for(int j = i - ;j >= ;j --)
if(S[j].x < S[i].x && S[j].y < S[i].y)
max = max > DP[j] ? max : DP[j];
if(max != -)
DP[i] += max;
ans = ans > DP[i] ? ans : DP[i];
}
printf("Case %d: maximum height = %d\n",count,ans);
} return ;
} void ex(const Node & r)
{
++ COUNT;
S[COUNT] = r;
swap(S[COUNT].y,S[COUNT].z); ++ COUNT;
S[COUNT] = r;
swap(S[COUNT].x,S[COUNT].y); ++ COUNT;
S[COUNT] = S[COUNT - ];
swap(S[COUNT].y,S[COUNT].z); ++ COUNT;
S[COUNT] = S[COUNT - ];
swap(S[COUNT].x,S[COUNT].z); ++ COUNT;
S[COUNT] = S[COUNT - ];
swap(S[COUNT].y,S[COUNT].z); ++ COUNT;
} bool comp(const Node & r_1,const Node & r_2)
{
if(r_1.x == r_2.x)
return r_1.y < r_2.y;
return r_1.x < r_2.x;
}

怒刷DP之 HDU 1069的更多相关文章

  1. 怒刷DP之 HDU 1257

    最少拦截系统 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  2. 怒刷DP之 HDU 1160

    FatMouse's Speed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Su ...

  3. 怒刷DP之 HDU 1260

    Tickets Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Stat ...

  4. 怒刷DP之 HDU 1176

    免费馅饼 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status  ...

  5. 怒刷DP之 HDU 1087

    Super Jumping! Jumping! Jumping! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64 ...

  6. 怒刷DP之 HDU 1114

    Piggy-Bank Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit S ...

  7. 怒刷DP之 HDU 1024

    Max Sum Plus Plus Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  8. 怒刷DP之 HDU 1029

    Ignatius and the Princess IV Time Limit:1000MS     Memory Limit:32767KB     64bit IO Format:%I64d &a ...

  9. HDU 1069 dp最长递增子序列

    B - Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I6 ...

随机推荐

  1. C#泛型在unity3D中的运用...

    泛型是什么? 这是摘自百度百科中对泛型的介绍: 泛型是c#2.0的一个新增加的特性,它为使用c#语言编写面向对象程序增加了极大的效力和灵活性.不会强行对值类型进行装箱和拆箱,或对引用类型进行向下强制类 ...

  2. android 检测ListView滚动到的位置

    ListView滚动 1.要用到一个监听事件是:setOnScrollListener(); API解释是: Set the listener that will receive notificati ...

  3. sqlserver锁表、解锁、查看锁表

    sqlserver锁表.解锁.查看锁表 http://www.cnblogs.com/zfanlong1314/p/3698566.html http://www.cnblogs.com/chjf20 ...

  4. Java中static的用法

    static静态,作为修饰符,最初是由c引入,一开始static表示退出一个块后依然存在的局部变量.随后,static表示不能被其他文件访问的全局变量和函数.到了C++和java,static表示属于 ...

  5. xampp 修改mysql 密码

    编辑 lampp/etc/extral/httpd-xampp.conf 文件注释掉 连上mysql,修改mysql下root 用户的登入密码为123456,执行 UPDATE user SET pa ...

  6. 全代码实现ios-2

    全代码开发ios第一个应用程序,完全像是盲人摸象. 首先,要设计这个应用,无论从界面,还是颜色搭配,以及功能,都是一个人完成. 也许,做独立开发人真的相当不容易. 因为,没有人帮忙给意见,而且,也没有 ...

  7. Instant Buy Android API Tutorial

    转自:https://developers.google.com/wallet/instant-buy/android/tutorial This tutorial guides you throug ...

  8. Hadoop on Mac with IntelliJ IDEA - 6 解决KeyValueTextInputFormat读取时只有key值问题

    本文讲述使用KeyValueTextInputFormat在Hadoop 0.x正常工作.Hadoop 1.2.1失效的解决过程. 环境:Mac OS X 10.9.5, IntelliJ IDEA ...

  9. WAF指纹探测及识别技术<freebuf>

    Web应用防护系统(也称:网站应用级入侵防御系统.英文:Web Application Firewall,简称: WAF).利用国际上公认的一种说法:Web应用防火墙是通过执行一系列针对HTTP/HT ...

  10. GPS获取Location 获取所在地点的经纬度

    利用手机获取所在地点的经纬度: Location 在Android 开发中还是经常用到的,比如 通过经纬度获取天气,根据Location 获取所在地区详细Address (比如Google Map 开 ...