B - Monkey and Banana

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

Appoint description:

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
 
 
每个格子可以形成6种状态,最多有180种状态,,,,,,,对X,Y作为判断条件进行判断,累加Z值
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
struct node{
int x,y,z;
}que[];
int dp[];
int tot; void addedge(int x,int y,int z){
que[tot].x=x;
que[tot].y=y;
que[tot++].z=z; que[tot].x=x;
que[tot].y=z;
que[tot++].z=y; que[tot].x=y;
que[tot].y=x;
que[tot++].z=z; que[tot].x=y;
que[tot].y=z;
que[tot++].z=x; que[tot].x=z;
que[tot].y=x;
que[tot++].z=y; que[tot].x=z;
que[tot].y=y;
que[tot++].z=x;
} bool cmp(struct node t1,struct node t2){
if(t1.x!=t2.x)
return t1.x>t2.x;
else if(t1.x==t2.x&&t1.y!=t2.y)
return t1.y>t2.y;
else
return t1.z>t2.z;
} int main(){
int n;
int cas=;
while(scanf("%d",&n)!=EOF){
if(!n)
break;
memset(dp,,sizeof(dp));
tot=;
int x,y,z;
for(int i=;i<n;i++){
scanf("%d%d%d",&x,&y,&z);
addedge(x,y,z);
}
sort(que+,que+tot+,cmp);
dp[]=que[].z;
for(int i=;i<tot;i++){
dp[i]=que[i].z;
for(int j=i-;j>=;j--){
if(que[i].x<que[j].x&&que[i].y<que[j].y&&dp[i]<dp[j]+que[i].z)
dp[i]=dp[j]+que[i].z;
}
}
int ans=-;
for(int i=;i<tot;i++)
ans=max(ans,dp[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'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. 求解最长递增子序列(LIS) | 动态规划(DP)+ 二分法

    1.题目描述     给定数组arr,返回arr的最长递增子序列. 2.举例     arr={2,1,5,3,6,4,8,9,7},返回的最长递增子序列为{1,3,4,8,9}. 3.解答      ...

随机推荐

  1. BaKoMa Tex Word 的使用

    数学论文编排软件,付费,但是可以这么处理,安装好后不要马上打开,进入影子系统的时候再运行它,这样每次都是全新的, 优势是 WYSIWYG,所见即所得, 中文输入, \documentclass{art ...

  2. Thrift 的原理和使用

    thrift 的原理和使用 Thrift 架构 Thrift是一个跨语言的服务部署框架,最初由Facebook于2007年开发,2008年进入Apache开源项目.Thrift通过IDL(Interf ...

  3. 工具,百度编辑器 UEditor 使用实例化

    <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...

  4. 缺少索引导致的服务器和MYSQL故障。

    故障现象: 网站访问缓慢. 数据库RDS: CPU满,连接数满,其他值都是空闲. apache服务器:CPU正常,IO正常,流量报警,内存爆满. 解决思路: 一.没遇到过此情况,一脸懵逼. 二.请教大 ...

  5. 关于hibernate纯sql查询返回结果集的问题(hbm.xml中不写多表关联)

    相信用过hibernate的兄弟们都会因为多表复杂查询后,为返回的结果如何组装到一个VO中而烦恼不已.我也不停的为此而烦恼,但是在看了hibernate的transform后,感觉这个方法还挺管用的. ...

  6. java的集合框架最全详解

    java的集合框架最全详解(图) 前言:数据结构对程序设计有着深远的影响,在面向过程的C语言中,数据库结构用struct来描述,而在面向对象的编程中,数据结构是用类来描述的,并且包含有对该数据结构操作 ...

  7. PHP: 手把手编写自己的 MVC 框架实例教程

    1 什么是MVC MVC模式(Model-View-Controller)是软件工程中的一种软件架构模式,把软件系统分为三个基本部分:模型(Model).视图(View)和控制器(Controller ...

  8. spring缓存Ehcache(入门2)源码解读

    Ehcache缓存: 解读: Ehcache缓存是在继承spring缓存核心类CacheManager的基础上实现的. 常用类: EhCacheCacheManager:继承自CacheManager ...

  9. Linux中postfix邮件服务器的搭建

    postfix是Wietse Venema在IBM的GPL协议之下开发的MTA(邮件传输代理)软件.postfix是Wietse Venema想要为使用最广泛的sendmail提供替代品的一个尝试.在 ...

  10. cf#305 Mike and Foam(容斥)

    C. Mike and Foam time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...