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. CentOS下crond定时任务详细介绍

    目录 1.定时任务crond介绍... 2.crond定时任务限权... 3.Crontab用法... 4.Crontab命令的书写格式... 5.定时服务器时间同步... 6.写定时任务注意点.. ...

  2. JS实现表格排序

    今天有点闲,写个小东西,使用JS实现点击表格标题栏实现自动排序功能,嘻嘻... 一.JS代码,文件名为code.js如下: (function($){ //插件 $.extend($,{ //命名空间 ...

  3. Markdown 简明语法手册

    Markdown 简明语法手册 本文原文http://www.jianshu.com/p/fdb5cbdaf244 根据个人使用情况有所修改. Markdown是一种轻量级标记语言,简称md.创始人为 ...

  4. jQM基本代码

    <div data-role="page"> <div data-role="header" data-position="fixe ...

  5. JabRef 文献管理软件

    JabRef 文献管理软件简明教程 大多只有使用LaTeX撰写科技论文的研究人员才能完全领略到JabRef的妙不可言,但随着对Word写作平台上BibTeX4Word插件的开发和便利应用,使用Word ...

  6. 浅谈JavaScript中的定时器

    引言 使用setTimeout()和setInterval()创建的定时器可以实现很多有意思的功能.很多人认为定时器是一个单独的线程(之前我也是),但是JavaScript是运行在单线程环境中的,而定 ...

  7. Jedis 例子(demo)大全

    第一步:到git下载jedis源码,如果你用maven或者gradle,那么直接下官方的即可,地址:https://github.com/xetorthio/jedis:如果你用ant,下载这个:ht ...

  8. php中的正则函数主要有三个-正则匹配,正则替换

    php中变量的声明? 由于php声明变量的时候, 不支持使用 var关键字, 又不能直接写一个变量名字, 孤零零的放在那里, 所以, 在php中声明变量的方式, 同时也是给变量初始化的形式, 即: & ...

  9. iOS: 聊聊 Designated Initializer(指定初始化函数)

    iOS: 聊聊 Designated Initializer(指定初始化函数) 一.iOS的对象创建和初始化 iOS 中对象创建是分两步完成: 分配内存 初始化对象的成员变量 我们最熟悉的创建NSOb ...

  10. LYDSY模拟赛day3 平均数

    [ 问题描述]有一天, 小 A 得到了一个长度为 n 的序列.他把这个序列的所有连续子序列都列了出来, 并对每一个子序列都求了其平均值, 然后他把这些平均值写在纸上, 并对它们进行排序,最后他报出了第 ...