本题大意:给出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. leetcode990

    class Finder: def __init__(self): self.Parent = [i for i in range(26)] def union(self, p, q): self.P ...

  2. USB之HID类Set_Report Request[调试手记1]

    请翻开<Device Class Definition for Human Interface Devices (HID) Version 1.11 >7.2.2 Set_Report R ...

  3. git的团队协作开发

    title: git的团队协作开发 date: 2018-04-24 14:00:03 tags: [git] --- 项目负责人创建组织架构 在控制面板中点击组织按钮,添加组织,在这里可以把组织理解 ...

  4. Mycat 水平拆分

    一致性Hash理解 https://blog.csdn.net/cywosp/article/details/23397179?utm_source=blogxgwz1 十种 水平拆分 https:/ ...

  5. java序列化问题

    今天无意中看到了     redistemplet封装的类中,出现了序列化的字眼 ,了解下序列化的知识 1.什么是序列化 我们把变量从内存中变成可存储或传输的过程称之为序列化,(java中一般是用来保 ...

  6. ACM__容器之vector

    今天做题碰到了深搜的题,有一种存图方式需要用到vector,对vector不是很熟悉,回顾了一下 vector都知道是一个容器,但并不准确,它是一个多功能的能够操作多种数据结构和算法的模板类和函数库. ...

  7. List根据时间字符串排序

    Collections.sort(resList, new Comparator<LoanApplyLogRes>() { @Override public int compare(Loa ...

  8. mybatis 获取insert返回的主键

    在我们开发过程中,在插入数据到数据库时,很多时候都需要把其主键返回,这里就说一下mybatis是怎么获取的. 其中mysql和oracle是不同的做法,因为mysql本身就提供字段自增的属性,而ora ...

  9. 4.Java的流程控制.md

    目录 1. break语句 2.continue 3.foreach语句 4.可变参数: 1. break语句 Java的break语句,正常情况下,break和c++一样,但是Java可以设置一个标 ...

  10. 有关于tomcat启动时,利用listener来执行某个方法

    今天,项目经理让我调查一下(目的是锻炼我),刚开始的时候说用listener来实现服务器启动然后某个项目跟着启动.其实就是tomcat启动的时候去执行某个方法,通过这个方法启动某个项目.我网上调查了一 ...