题目

题意:研究人员要测试猴子的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. CUDA compiler driver nvcc 散点 part 1

    ▶ 参考[https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html] ▶ nvcc 预定义的宏 __NVCC__ // 编译 ...

  2. vmware 里MAC 鼠标能移动 无法单击

    vmware 里MAC  鼠标能移动 无法单击 移动有效果,能看到鼠标移动的光标,鼠标放到mac的图标上还有提示,就是无法单击. 键盘正常. 重启mac,重启vmware 20次好了,2小时.

  3. Sql Server数据库之流程定义变量和流程控制语句

    一.局部变量和全局变量 1.声明局部变量 语法:declare @变量名 变量类型 2.给局部变量赋值 语法:set @变量名=值,         select @变量名=值 区别:第一种方式用于普 ...

  4. 2017-11-04 Sa Oct 消参

    2017-11-04 Sa $ P(-3, 0) $ 在圆C $ (x-3)^2 + y^2 = 8^2 $ 内,动圆M与圆相切且过P点,求M点轨迹. 设切点 $ A(a, b) $,圆心 \(M(x ...

  5. linux上安装字体

    安装字体命令: yum install wqy-microhei-fonts wqy-zenhei-fonts   安装完字体的存放目录:/usr/share/fonts   默认会在fonts目录下 ...

  6. 配置MQTT服务器

    第一步:下载一个Xshell 链接:https://pan.baidu.com/s/16oDa5aPw3G6RIQSwaV8vqw 提取码:zsb4 打开Xshell 前往MQTT服务器软件下载地址: ...

  7. AltiumDesigner PCB中栅格与格点的切换

    PCB中通过快捷键Ctrl+G,进入设置界面. 在弹出的对话框中,在Display,Coarse选择Lines为栅格,Dots为格点,Do Not Draw为无任何显示.

  8. MYSQL 时间类型

    常见四种:DATE, TIME, DATETIME, TIMESTAMP DATE: 只表示年月日,YYYY-MM-DD TIME: 只表示时分秒,HH-mm-SS DATETIME: DATE和TI ...

  9. POJ 1741 Tree(点分治点对<=k)

    Description Give a tree with n vertices,each edge has a length(positive integer less than 1001). Def ...

  10. canvas(二) lineCap demo

    var dom = document.getElementById('clock'), ctx = dom.getContext('2d'); ctx.beginPath(); ctx.moveTo( ...