题目:这里

题意:

Description

一组研究人员正在设计一项实验,以测试猴子的智商。他们将挂香蕉在建筑物的屋顶,同时,提供一些砖块给这些猴子。如果猴子足够聪明,它应当能够通过合理的放置一些砖块建立一个塔,并爬上去吃他们最喜欢的香蕉。
 
研究人员有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
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

Sample Output

Case 1: maximum height = 40
Case 2: maximum height = 21

Case 3: maximum height = 28

Case 4: maximum height = 342 
 
一种砖虽然有无数个,最多用两个,因为从小往上看是递减的,下面的只能大于上面,连等于都不行,长宽高三个性质,全排列有六种,将所有砖块的这六种排列排序
,长从大到小,如果长相等,就按宽从大到小,这样排序之后,就变成了求最大单调子序列了。
 
 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std; struct node{
int h,v,l;
}re[];
int dp[]; int max(int x,int y) {return x>y?x:y;} bool cmp(node a,node b)
{
if (a.l==b.l)
{
if (a.v==b.v)
return a.h>b.h;
return a.v>b.v;
}
return a.l>b.l;
} int main()
{
int n,tem=;
while (~scanf("%d",&n)&&n)
{
int cas=;
for (int i= ; i<=n ; i++)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
re[++cas].l=x,re[cas].h=y,re[cas].v=z;
re[++cas].l=z,re[cas].h=y,re[cas].v=x;
re[++cas].l=x,re[cas].h=z,re[cas].v=y;
re[++cas].l=y,re[cas].h=z,re[cas].v=x;
re[++cas].l=z,re[cas].h=x,re[cas].v=y;
re[++cas].l=y,re[cas].h=x,re[cas].v=z;
}
sort(re+,re+cas+,cmp);
for (int i= ; i<=cas ; i++)
{
dp[i]=re[i].h;
for (int j= ; j<i ; j++)
{
if (re[i].l<re[j].l&&re[i].v<re[j].v)
dp[i]=max(dp[i],dp[j]+re[i].h);
}
}
int ans=;
for (int i= ; i<=cas ; i++)
ans=max(ans,dp[i]);
printf("Case %d: maximum height = %d\n",++tem,ans);
}
return ;
}
 
 

hdu 1069 (DP) Monkey and Banana的更多相关文章

  1. HDU 1069:Monkey and Banana(DP)

    Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  2. 【HDU - 1069】 Monkey and Banana (基础dp)

    Monkey and Banana 直接写中文了 Problem Statement 一组研究人员正在设计一项实验,以测试猴子的智商.他们将挂香蕉在建筑物的屋顶,同时,提供一些砖块给这些猴子.如果猴子 ...

  3. HDU 1069 dp最长递增子序列

    B - Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I6 ...

  4. HDU 1069---背包---Monkey and Banana

    HDU 1069 Description A group of researchers are designing an experiment to test the IQ of a monkey. ...

  5. HDU 1069 Monkey and Banana (DP)

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

  6. HDU 1069—— Monkey and Banana——————【dp】

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

  7. HDU 1069 Monkey and Banana dp 题解

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

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

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

  9. HDU 1069 Monkey and Banana 基础DP

    题目链接:Monkey and Banana 大意:给出n种箱子的长宽高.每种不限个数.可以堆叠.询问可以达到的最高高度是多少. 要求两个箱子堆叠的时候叠加的面.上面的面的两维长度都严格小于下面的. ...

随机推荐

  1. git&sourcetree安装及在IntelliIJ下拉取项目基础使用

    be careful: 1)git版本与Sourcetree版本最好一致 ,不能git为2.5,sourcetree为1.8 2)先安装git再安装Sourcetree 3)拥有git和sourcet ...

  2. php-fpm 在centos 7下的安装配置

    安装php: sudo yum install php php-fpm php-mysql php-mbstring php-mcrypt php-sockets php-curl php-commo ...

  3. 老生长谈,温故知新:css实现右侧固定宽度,左侧宽度自适应

    反过来也可以:左侧宽度固定,右侧自适应.不管是左是右,反正就是一边宽度固定,一边宽度自适应. 这种布局比较常见,博客园很多默认主题就是这种.一般情况下,这种布局中宽度固定的区域是侧边栏,而自适应的区域 ...

  4. 使用Birt开发报表

    间隔一段时间未使用Birt开发报表后,本文章记录Birt开发报表的常遇到的开发问题及解决措施,方便自己和园内其他朋友学习. 一.Birt连接数据库配置 1.连接DB2数据库: 1.1.birt的数据连 ...

  5. mongodb 分组查询

    数据的保存 include_once 'mDB.class.php'; $m=new mDB(); $m->setDB('mydb'); // $m->save('stu',['dept' ...

  6. 一个C#语法高亮插件

    语法高亮对程序员阅读代码来说有着不小的帮助,虽然VisualStudio本身支持C#语法高亮,但也只是对关键字.类名.字符串等少数元素加了标记,而我们代码中主题:变量.函数.属性.事件等都没有进行高亮 ...

  7. listview侧滑菜单swipemenulistview的简单使用

    先看代码: public class MainActivity extends AppCompatActivity { private SwipeMenuListView list; private ...

  8. php下载网络图片到服务器

    /** * 下载二维码到服务器 * @param string $url 图片路径 * @param string $filestring 要保存的文件名 */    private function ...

  9. MySQL中存储过程+事件的使用方法

    一.背景 将界面操作日志存储在MySQL数据库中的operationlog表中,如果该表不能自动备份,表中的数据会越来越多,影响速度.可以定期将表中数据备份到另外一个表中来解决. 二.解决方案 1.使 ...

  10. Angular JS中$timeout的用法及其与window.setTimeout的区别

    $timeout的用法 angular.js的$timeout指令对window.setTimeout做了一个封装,它的返回值是一个promise对象.当定义的时间到了以后,这个promise对象就会 ...