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. AP(应付帐管理)

    --更新供应商地点 PROCEDURE update_vendor_site(p_init_msg_list IN VARCHAR2 DEFAULT fnd_api.g_false, x_return ...

  2. Java程序内存分析:使用mat工具分析内存占用

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...

  3. Queue and Message

    #ifndef __QUEUE_H__ #define __QUEUE_H__ #include <stdint.h> #include <stdlib.h> #include ...

  4. Slony-I的 RemoteWorker重试调查

    客户的问题是: 向Slony-I运行环境中,增加新的slaveDB节点的时候发生错误. log中反复出现错误,然后再重新开始(重新开始部分的log省略): CONFIG remoteWorkerThr ...

  5. UVA 1108 - Mining Your Own Business

    刘汝佳书上都给出了完整的代码 在这里理一下思路: 由题意知肯定存在一个或者多个双连通分量: 假设某一个双连通分量有割顶.那太平井一定不能打在割顶上. 而是选择割顶之外的随意一个点: 假设没有割顶,则要 ...

  6. 【M10】在构造方法内阻止资源泄漏

    1.类中没有指针,如果对象构造过程中出现异常,C++保证已经构造好的那一部分自动销毁.注意:这里不是调用析构方法,而是编译器在你的构造方法中插入了一些代码,保证对已经构造好的对象析构. 2.类中有指针 ...

  7. 仿Android网易新闻客户端,并增加水平图片滑动,改进阅读体验

    仿网易新闻Android端APP 主要功能展示和代码实现 差不多花了一周的时间,目前实现的了新闻下的包括头条.体育.娱乐的一系列的新闻展示,以及点击后进入的新闻详情展示. 目前效果 目前效果请访问该网 ...

  8. oracle where 后面的条件中|| 是什么意思

    oracle where 后面的条件中|| 是连接符号,Oracle中另一个concat函数能够连接两个字符串 concat(a,b) Oracle中nvl函数的使用方法和作用是什么? 假设你某个字段 ...

  9. handler looper 和 线程

     Handler的概念: 顾名思义,handler在英语中是“操作着,处理者的意思”,而官方的文档给出的概念是,handler允许你发送或者处理Message对象或者Runable对象,这两个对象都是 ...

  10. IOS文件系统和数据的永久性存储

    IOS中的文件系统和数据的永久性存储 目录 概述——对文件系统和数据的永久性存储的理解 IOS中数据的永久性存储 NSUserDefaults 解档和归档 数据库 文件系统 NSBundle IOS的 ...