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. Contributing to Open Source on GitHub(转)

    A great way to get involved in open source is to contribute to the existing projects you’re using. G ...

  2. USACO Section 5.3 Milk Measuring (IDDFS+dp)

    迭代加深搜索,从小到大枚举桶数的上限maxd:对每个maxd,枚举每个组合,判断是否能够倒出q:直到得到answer.判断的部分就用dp(完全背包). ------------------------ ...

  3. Spring学习之Aop的各种增强方法

    AspectJ允许使用注解用于定义切面.切入点和增强处理,而Spring框架则可以识别并根据这些注解来生成AOP代理.Spring只是使用了和AspectJ 5一样的注解,但并没有使用AspectJ的 ...

  4. mysql修改用户名和密码

    修改用户名 mysql> use mysql;  选择数据库Database changedmysql> update user set user="dns" wher ...

  5. javascript函数querySelector

    querySelector用于获得dom节点,可以接受三种类型的参数:id(#),class(.),标签.很像jquery的选择器.不过只能返回一个子孙元素,但是jquery选择器的话,可以返回一组元 ...

  6. PHP CI框架最近学到的内容

    CI框架配置方面注意的细节 在config里面的database.php里面是和数据库配置相关的内容 $db['default'] = array( 'dsn' => '', 'hostname ...

  7. Qt 智能指针学习(7种QT的特有指针)

    从内存泄露开始? 很简单的入门程序,应该比较熟悉吧 ^_^ #include <QApplication> #include <QLabel> int main(int arg ...

  8. Python+django开发环境搭建

    Python目前主版本有2个,2.7+和3.4+ 新入手,决定还是从2.7开始 先从python官网https://www.python.org/下载python2.7.10,64位版本(这里注意,选 ...

  9. Flex疑难小杂症

    本文主要解决Flex中一些小问题,收集一些小技巧(来自网络及个人经验) flex自动换行问题  有时候由于label .button等控件中需要用到text属性显示出文本,文本太长就涉及到换行问题,解 ...

  10. [Python]Unicode转ascii码的一个好方法

    写这篇文章的是一位外国人,他遇到了什么问题呢?比如有一个 Unicode 字符串他需要转为 ascii码: >>> title = u"Klüft skräms inför ...