本题大意:给出n个长方体,每种长方体不限量,让你求出如何摆放长方体使得最后得到的总高最大,摆设要求为,底层的长严格大于下层的长,底层的宽严格大于下层的宽。

  本题思路:一开始没有啥思路...首先应该想到如果数组内的长宽等都是乱序的话会很影响计算的效率,所以我们先进行排序,对于每种长方体,我们将其三种摆放方式存入数组,然后利用sort排序,

我们会得到一个按照长度递增,长度相等则按照宽度递增的顺序摆放,最后很明显就可以得出状态转移方程:dp[ i ] = max(dp[ j ]) + a[ i ]. h;

  参考代码:

 //2019.3.28
//用dp[i]表示前i个长方体的最优解 dp[i] = max(dp[j] + a[j].h)(j < i);
//无序就手动构造有序,呜呜呜~~~
#include <iostream>
#include <algorithm>
using namespace std; const int maxn = ( + ) * ;
int n, Case = , num, max_h;
struct node {
int l, c, h;
} a[maxn];
int dp[maxn]; bool cmp(const node a, const node b) {
if(a.l == b.l) return a.c < b.c;
return a.l < b.l;
} int main () {
int z1, z2, z3;
while(cin >> n && n) {
num = ;//记录可变换长方体的总个数
for(int i = ; i < n; i ++) {
cin >> z1 >> z2 >> z3;
a[num].h = z1, a[num]. l = z2 > z3 ? z2 : z3, a[num ++].c = z2 < z3 ? z2 : z3;
a[num].h = z2, a[num]. l = z1 > z3 ? z1 : z3, a[num ++].c = z1 < z3 ? z1 : z3;
a[num].h = z3, a[num]. l = z1 > z2 ? z1 : z2, a[num ++].c = z1 < z2 ? z1 : z2;
}
sort(a, a + num, cmp);
dp[] = a[].h;
for(int i = ; i < num; i ++) {
max_h = ;
for(int j = ; j < i; j ++) {
if(a[j].l < a[i].l && a[j].c < a[i].c)
max_h = max_h > dp[j] ? max_h : dp[j];
}
dp[i] = a[i].h + max_h;
}
cout << "Case " << ++ Case << ": maximum height = " << *max_element(dp, dp + num) << endl;
}
return ;
}

  这里本弱用到了一个经常不用的函数*max_element,大家可以遍历一遍数组找最大值也可以。

HDU-1069.MonkeyandBanana(LIS)的更多相关文章

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

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

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

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

  3. HDU 1069&&HDU 1087 (DP 最长序列之和)

    H - Super Jumping! Jumping! Jumping! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format: ...

  4. 怒刷DP之 HDU 1069

    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 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

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

  7. (最大上升子序列)Monkey and Banana -- hdu -- 1069

    http://acm.hdu.edu.cn/showproblem.php?pid=1069      Monkey and Banana Time Limit:1000MS     Memory L ...

  8. hdu 1069 动规 Monkey and Banana

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

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

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

  10. HDU 1069 Monkey and Banana dp 题解

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

随机推荐

  1. JS call和apply方法使用

    总是对call和apply方法使用存在迷惑,特此记录一下 一句话理解这两个方法: call和apply是为了动态改变this而出现的,当一个object没有某个方法,但是其他的有,我们可以借助call ...

  2. linux驱动开发( 五) 字符设备驱动框架的填充file_operations结构体中的操作函数(read write llseek unlocked_ioctl)

    例子就直接使用宋宝华的书上例子. /* * a simple char device driver: globalmem without mutex * * Copyright (C) 2014 Ba ...

  3. struts2中的constant介绍之struts.objectFactory与spring的整合

    struts2提供给我们更为灵活的设计,他的很多东西都是可以手动配置的,下面介绍下他的一些 常用的constant作用和配置 struts.objectFactory这个属性用于说明Struts2的 ...

  4. mybatisGenerator自动生成pojo、dao、xml文件

    一.简介: mybatisGenerator是一款自动生成文件工具.本文使用idea2017.3.1来进行操作. 二.文件生成之后的项目结构: 三.开始生成步骤: 1.使用idea生成maven的结构 ...

  5. linux终端发送邮件

    使用mail: echo "This is message to send" | mail -a /tmp/attachment.txt -s "This is Subj ...

  6. vue:一个vue可以使用的视频插件

    网址:https://www.jianshu.com/p/e8e747e33ef0 1:安装依赖 npm install vue-video-player -S 2:引入配置(main.js) imp ...

  7. 高质量C++/C编程指南

    http://man.chinaunix.net/develop/c&c++/c/c.htm#_Toc520634042 高质量C++/C编程指南 文件状态 [  ] 草稿文件 [√] 正式文 ...

  8. python实现Excel删除特定行、拷贝指定行操作

    工作中遇到的,本来用VBA写的,操作很慢,尝试用Python实现, 任务需求: 从原始的两张表中拷贝行到五张表中,如下表所示: source1和source2是一样的格式:         one t ...

  9. [namespace]PHP命名空间的使用基础

    -------------------------------------------------------------------------------------------------- 一 ...

  10. 在springboot中 使用jsp