题目

题意:研究人员要测试猴子的IQ,将香蕉挂到一定高度,给猴子一些不同大小的箱子,箱子数量不限,让猩猩通过叠长方体来够到香蕉。 现在给你N种长方体, 要求:位于上面的长方体的长和宽  要小于  下面长方体的长和宽。

思路:对于一种长方体,长宽高(a,b,c)有6总不同的组成方式{(a,b,c),(a,c,b),(b,a,c),(b,c,a),(c,a,b),(c,b,a) },对所有组成方式的长方体从小到大排序,比较满足长1<长2,宽1<宽2,的最大高度。

dp[i]: 表示第i个盒子的高 + 前i-1个盒子在满足(x1<x2,y1<y2)的情况下可以组成的最大的高度

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int Max = 200+10;
//dp[i]:表示第i个盒子的高+前i-1个盒子在满足(x1<x2,y1<y2)的情况下可以组成的最大的高
int dp[Max];
struct node{
int x,y,z;
};
node no[Max];
int cmp(node a,node b)
{
if(a.x==b.x) return a.y<b.y;
else return a.x<b.x;
}
int main()
{
int n,x,y,z;
int Case =1;
while(cin>>n)
{
if(n==0) break;
int cnt = 0;
for(int i=0;i<n;i++)
{
cin>> x >> y >>z;
no[cnt].x = x,no[cnt].y=y,no[cnt++].z=z;
no[cnt].x = x,no[cnt].y=z,no[cnt++].z=y;
no[cnt].x = y,no[cnt].y=x,no[cnt++].z=z;
no[cnt].x = y,no[cnt].y=z,no[cnt++].z=x;
no[cnt].x = z,no[cnt].y=x,no[cnt++].z=y;
no[cnt].x = z,no[cnt].y=y,no[cnt++].z=x;
}
sort(no,no+cnt,cmp);
dp[0]=no[0].z;
int maxh;
for(int i=1;i<cnt;i++)
{
maxh=0;
for(int j=0;j<i;j++)
{
if(no[j].x<no[i].x&&no[j].y<no[i].y)
maxh = max(maxh,dp[j]);;
}
dp[i] = no[i].z+maxh;
}
maxh=0;
for(int i=0;i<cnt;i++)
if(dp[i]>maxh) maxh = dp[i];
printf("Case %d: maximum height = %d\n",Case++,maxh);
}
return 0;
}

hdu 1069 Monkey and Banana 【动态规划】的更多相关文章

  1. 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 ...

  2. HDU 1069 Monkey and Banana dp 题解

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

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

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

  4. HDU 1069 Monkey and Banana(动态规划)

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

  5. HDU 1069 Monkey and Banana (动态规划、上升子序列最大和)

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

  6. HDU 1069 Monkey and Banana(二维偏序LIS的应用)

    ---恢复内容开始--- Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  7. HDU 1069 Monkey and Banana (DP)

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

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

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

  9. hdu 1069 Monkey and Banana

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

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

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

随机推荐

  1. OOM三种情况

    第一种OutOfMemoryError: PermGen space发生这种问题的原意是程序中使用了大量的jar或class,使java虚拟机装载类的空间不够,与Permanent Generatio ...

  2. win10 64位,家庭版,C++,ini配置说明

      #include<windows.h> #include<iostream> #include <atlstr.h> using namespace std; ...

  3. 保持ssh连接长时间不断开的技巧

    我经常用ssh连接服务器,过段时间不用, 需要恢复一下断开的连接, 原因是NAT防火墙喜欢对空闲的会话进行超时处理,以确保它们状态表的干净和内存的低占用率,因为 长时间保持连接, 会长期占用部分系统资 ...

  4. 配置yum源

    本文转载:https://www.cnblogs.com/yangp/p/8506264.html (一)yum源概述 yum需要一个yum库,也就是yum源.默认情况下,CentOS就有一个yum源 ...

  5. java网络编程-单线程服务端与客户端通信

    该服务器一次只能处理一个客户端请求;p/** * 利用Socket进行简单服务端与客户端连接 * 这是服务端 */public class EchoServer { private ServerSoc ...

  6. leetcode31

    class Solution { public: void nextPermutation(vector<int>&nums) { int len = nums.size(); , ...

  7. css:清楚html所有标签自带属性

    相信如果您动手写过网页的话,应该体会到有些标签会自带一些默认的样式,而这些样式或许又是我们不想要的,所以我们可以用以下代码清除所有标签的默认样式   html, body, div, span, ap ...

  8. get_time

    def get_current_time(): #将python的datetime转换为unix时间戳 dtime = datetime.datetime.now() un_time = time.m ...

  9. [Ting's笔记Day2]在Github用Jekyll创建自己的blog

    昨天工程师在我们共同的群组分享他的blog,他提到是使用Jekyll(一个简单静态blog网站生成器)架在github上的. 于是好奇的我决定照着关键字来搜寻一下,如法炮制做一个出来. 也可以放一份到 ...

  10. prometheus 表达式

    avg_over_time(my_inprogress_requests{job="mhc"}[5m] offset 3m) 返回time=1550664637开始向前偏移3分钟之 ...