Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64uDescription
一组研究人员正在设计一项实验,以测试猴子的智商。他们将挂香蕉在建筑物的屋顶,同时,提供一些砖块给这些猴子。如果猴子足够聪明,它应当能够通过合理的放置一些砖块建立一个塔,并爬上去吃他们最喜欢的香蕉。
 
研究人员有n种类型的砖块,每种类型的砖块都有无限个。第i块砖块的长宽高分别用xi,yi,zi来表示。 同时,由于砖块是可以旋转的,每个砖块的3条边可以组成6种不同的长宽高。
 
在构建塔时,当且仅当A砖块的长和宽都分别小于B砖块的长和宽时,A砖块才能放到B砖块的上面,因为必须留有一些空间让猴子来踩。
 
你的任务是编写一个程序,计算猴子们最高可以堆出的砖块们的高度。

Input

输入文件包含多组测试数据。
每个测试用例的第一行包含一个整数n,代表不同种类的砖块数目。n<=30.
接下来n行,每行3个数,分别表示砖块的长宽高。
当n= 0的时候,无需输出任何答案,测试结束。

Output

对于每组测试数据,输出最大高度。格式:Case 第几组数据: maximum height = 最大高度

Sample Input

1
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 
程序分析:这是一道经典的动态规划题,这个其实可以看作背包01问题来看待,背包01问题的特点是每件物品仅有一件,可以选择放或者不放,其实这道题虽然说有无限个砖块,可是他每种砖块转换成6种状态之后,每种状态只可能出现一次,因为还有长和宽的限制。那么可以得到这个问题的最优子结构,用h[i]表示以第i个砖块作为最上面一个砖块可以得到的最大距离,为了保证其最优性,状态转移方程为h[i]=max{h[j],j<i},这个方程是因为事先经过排序,使得面积从大到小排,因此序号大于i的砖块不可能放在砖块i的下面。
程序代码:
#include"iostream"
#include"cstring"
#include"algorithm"
typedef long long ll;
using namespace std; const int maxn=+; int cass=; struct node
{
int x,y,z;
void get(int x2,int y2,int z2)
{
x=x2;
y=y2;
z=z2;
}
}a[maxn]; bool cmp(node a1,node a2)
{
int su1=a1.x*a1.y;
int su2=a2.x*a2.y;
return su1>su2;
} int n;
int k;
ll h[maxn]; bool is(node a1,node a2)
{
if(a1.x<a2.x&&a1.y<a2.y) return true;
return false;
} void Init()
{
int x1,y1,z1;
k=;
a[].x=a[].y=;
for(int i=;i<n;i++)
{
cin>>x1>>y1>>z1;
a[k++].get(x1,y1,z1);
a[k++].get(y1,x1,z1);
a[k++].get(z1,y1,x1);
a[k++].get(x1,z1,y1);
a[k++].get(y1,z1,x1);
a[k++].get(z1,x1,y1);
}
sort(a+,a+k+,cmp);
} void Work()
{
ll MAX=;
int i,j;
memset(h,,sizeof(h));
for(i=;i<k;i++)
{
for(j=;j<i;j++)
{
if(is(a[i],a[j])&&a[i].z+h[j]>h[i])
h[i]=a[i].z+h[j];
}
MAX=max(h[i],MAX);
}
cout<<"Case "<<++cass<<": maximum height = "<<MAX<<endl;
} int main()
{
while(cin>>n&&n)
{
Init();
Work();
}
return ;
}

HDU 1069 monkey an banana DP LIS的更多相关文章

  1. HDU 1069 Monkey and Banana DP LIS变形题

    http://acm.hdu.edu.cn/showproblem.php?pid=1069 意思就是给定n种箱子,每种箱子都有无限个,每种箱子都是有三个参数(x, y, z)来确定. 你可以选任意两 ...

  2. HDU 1069 Monkey and Banana DP LIS

    http://acm.hdu.edu.cn/showproblem.php?pid=1069 题目大意 一群研究员在研究猴子的智商(T T禽兽啊,欺负猴子!!!),他们决定在房顶放一串香蕉,并且给猴子 ...

  3. HDU 1069 Monkey and Banana dp 题解

    HDU 1069 Monkey and Banana 纵有疾风起 题目大意 一堆科学家研究猩猩的智商,给他M种长方体,每种N个.然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉. 现在给你M种 ...

  4. HDU 1069 Monkey and Banana (DP)

    Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  5. HDU 1069 Monkey and Banana(DP 长方体堆放问题)

    Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...

  6. HDU 1069 Monkey and Banana(LIS最长上升子序列)

    B - LIS Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Descripti ...

  7. hdu(1069)——Monkey and Banana(LIS变形)

    题意: 如今给你n个石块,然后它由坐标来表示(x,y,z).可是它能够有不同的方法,也就是说它的三个坐标能够轮换着来的. 石块的数量不限,可是每次都必须保持上底面的长和宽严格递减,然后问你用这些石块所 ...

  8. HDU 1069 Monkey and Banana / ZOJ 1093 Monkey and Banana (最长路径)

    HDU 1069 Monkey and Banana / ZOJ 1093 Monkey and Banana (最长路径) Description A group of researchers ar ...

  9. HDU 1069 Monkey and Banana(转换成LIS,做法很值得学习)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS (Java ...

随机推荐

  1. Linux C网络编程学习笔记

    Linux C网络编程总结报告 一.Linux C 网络编程知识介绍: 网络程序和普通的程序有一个最大的区别是网络程序是由两个部分组成的--客户端和服务器端. 客户端:(client) 在网络程序中, ...

  2. inline-block 垂直居中

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. LED板上芯片(COB)封装流程

    LED 板上芯片(Chip On Board,COB)封装流程是,首先在基底表面用导热环氧树脂(一般用掺银颗粒的环氧树脂)覆盖硅片安放点, 然后将硅片 间接安放正在基底表面,热处理至硅片牢固地固定正在 ...

  4. FreeBSD 10安装KDE桌面环境简介(亲测bsdconfig命令有效)

    FreeBSD 10出来一段时间了,自己摸索装上KDE环境,网上介绍的都是10以前版本的,要么对现在的不合适,走了一大圈弯路还是装不好:要么太繁琐且装了一堆无用的软件.本着让更多人能快速方面的入门Fr ...

  5. 转:详细解说 STL 排序(Sort)

    详细解说 STL 排序(Sort) 详细解说 STL 排序(Sort) 作者Winter 详细解说 STL 排序(Sort) 0 前言: STL,为什么你必须掌握 1 STL提供的Sort 算法 1. ...

  6. C++模板:字典树

    //插入 void insert(char *s,char *s1){ for(int l=strlen(s),x=0,i=0;i<l;i++){ if(!trie[x].son[s[i]-'a ...

  7. [置顶] 【J2SE 】1136 容器之旅

    开篇引言 本篇文章我将要详细的介绍一下什么是容器?以及什么是1136?来系统全面的了解容器,以及容器的应用,下面就进入我们的容器之旅吧! 1.什么是容器? 用来存储和组织其他对象的对象.我们也可以这样 ...

  8. HDU 4725 The Shortest Path in Nya Graph-【SPFA最短路】

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4725 题意:有N个点和N层..一层有X个点(0<=X<=N).两邻两层间有一条路花费C.还有M ...

  9. gridview的高级使用

      后台数据 using System; using System.Collections.Generic; using System.Linq; using System.Web; using Sy ...

  10. Oracle表解锁

    网搜 --第一步 查看被锁表 select b.owner,b.object_name, b.object_id,l.session_id,l.locked_mode from v$locked_ob ...