B - Monkey and Banana

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

Appoint 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.



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.


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

10 20 30
6 8 10
5 5 5
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
31 41 59
26 53 58
97 93 23
84 62 64
33 83 27

Sample Output

Case 1: maximum height = 40
Case 2: maximum height = 21
Case 3: maximum height = 28
Case 4: maximum height = 342
using namespace std;
struct node{
int x,y,z;
int dp[];
int tot; void addedge(int x,int y,int z){
que[tot++].z=z; que[tot].x=x;
que[tot++].z=y; que[tot].x=y;
que[tot++].z=z; que[tot].x=y;
que[tot++].z=x; que[tot].x=z;
que[tot++].z=y; que[tot].x=z;
} bool cmp(struct node t1,struct node t2){
return t1.x>t2.x;
else if(t1.x==t2.x&&t1.y!=t2.y)
return t1.y>t2.y;
return t1.z>t2.z;
} int main(){
int n;
int cas=;
int x,y,z;
for(int i=;i<n;i++){
for(int i=;i<tot;i++){
for(int j=i-;j>=;j--){
int ans=-;
for(int i=;i<tot;i++)
printf("Case %d: maximum height = %d\n",cas++,ans);
return ;

HDU 1069 dp最长递增子序列的更多相关文章

  1. [DP]最长递增子序列

    #include <iostream> #include <limits.h> #include <vector> #include <algorithm&g ...

  2. HDU-1160-FatMouse&#39;s Speed(DP, 最长递增子序列)

    链接: https://vjudge.net/problem/HDU-1160 题意: FatMouse believes that the fatter a mouse is, the faster ...

  3. hdu 1025 dp 最长上升子序列

    //Accepted 4372 KB 140 ms //dp 最长上升子序列 nlogn #include <cstdio> #include <cstring> #inclu ...

  4. poj 1631 Bridging signals (二分||DP||最长递增子序列)

    Bridging signals Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9234   Accepted: 5037 ...

  5. HDU 1257 最少拦截系统 最长递增子序列

    HDU 1257 最少拦截系统 最长递增子序列 题意 这个题的意思是说给你\(n\)个数,让你找到他最长的并且递增的子序列\((LIS)\).这里和最长公共子序列一样\((LCS)\)一样,子序列只要 ...

  6. dp之最长递增子序列模板poj3903

    最长递增子序列,Longest Increasing Subsequence 下面我们简记为 LIS.排序+LCS算法 以及 DP算法就忽略了,这两个太容易理解了. 假设存在一个序列d[1..9] = ...

  7. 动态规划(DP),最长递增子序列(LIS)

    题目链接:http://poj.org/problem?id=2533 解题报告: 状态转移方程: dp[i]表示以a[i]为结尾的LIS长度 状态转移方程: dp[0]=1; dp[i]=max(d ...

  8. Longest Increasing Subsequences(最长递增子序列)的两种DP实现

    一.本文内容 最长递增子序列的两种动态规划算法实现,O(n^2)及O(nlogn).     二.问题描述 最长递增子序列:给定一个序列,从该序列找出最长的 升序/递增 子序列. 特点:1.子序列不要 ...

  9. 51nod-1134 最长递增子序列,用线段树将N^2的dp降到NlogN

    题目链接 给出长度为N的数组,找出这个数组的最长递增子序列.(递增子序列是指,子序列的元素是递增的) 例如:5 1 6 8 2 4 5 10,最长递增子序列是1 2 4 5 10. Input 第1行 ...


  1. ASP.Net Core MVC6 RC2 启动过程分析[偏源码分析]

    入口程序 如果做过Web之外开发的人,应该记得这个是标准的Console或者Winform的入口.为什么会这样呢? .NET Web Development and Tools Blog ASP.NE ...

  2. java删除文件

    public boolean deleteFile(String fileName) { File file = new File("D:/NovaPluto/xml/"+file ...

  3. python套接字基本使用

    socket socket通常也称作"套接字",用于描述IP地址和端口,应用程序通常通过"套接字"向网络发出请求或者应答网络请求,可以认为是一种计算机网络的数据 ...

  4. SharePoint:WebPartPageUserException This page has encountered a critical error

    遇到如下webpart莫名错误,很常见吧.一般用户是直接删掉,知道原因的不算太多. 解决办法(Solution): Usually, This error caused by wrong entrie ...

  5. 重温WCF之发送和接收SOAP头(三)

    SOAP头可以理解为一种附加信息,就是附加到消息正文的内容. 既然消息头是附加信息,那有啥用呢?你可别说,有时候还真有不少用处.举个例子,WCF的身份验证是不是很麻烦?还要颁发什么证书的(当然不是荣誉 ...

  6. 自己使用python webob,paste.deploy,wsgi总结

    paste.deploy就是一个可以配置wsgi_app的工具,可以让服务器运行时,按照配置文件执行一系列的程序.需要使用.ini配置文件. (1)这里补充一下当时没看到的配置文件 1.[app:ma ...

  7. 创建TreeView控件

    第一种方式 hwndTreeView=CreateWindow("SysTreeView32", NULL,WS_CHILD|WS_VISIBLE|TVS_HASLINES|TVS ...

  8. linux下串口函数

    tcgetattr(), tcsetattr(), tcdrain(),tcflush(), tcflow(), tcsendbreak(),cfmakeraw(), cfgetispeed(),cf ...

  9. HoloLens开发手记 - 手势输入 Gesture input

    手势是HoloLens三个首要输入形式之一.一旦你使用凝视定位了一个全息图像,手势允许你与它交互.手势输入允许你使用手或者点击器原生地与全息图像交互. 手势之外,你也可以在应用中使用语音输入来交互. ...

  10. 使用pymysql操作数据库

    学习如何使用python的pymysql模块来操作mysql数据库 这里的基本用法主要借鉴了该篇博客:https://www.cnblogs.com/woider/p/5926744.html 因为这 ...