本题大意:给出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. WPF线性渐变画刷应用之——炫彩线条

    效果图: Xaml代码: <Rectangle Width="800" Height="10"> <Rectangle.Fill> &l ...

  2. Linux查看当前系统的发行版信息

    lsb_release命令用来查看当前系统的发行版信息(prints certain LSB (Linux Standard Base) and Distribution information.). ...

  3. 经典论文翻译导读之《Finding a needle in Haystack: Facebook’s photo storage》

    https://github.com/chrislusf/seaweedfs [译者预读]面对海量小文件的存储和检索,Google发表了GFS,淘宝开源了TFS,而Facebook又是如何应对千亿级别 ...

  4. Linux IP和网关配置

    操作环境 SuSE11/SuSE10 配置方法一<永久有效,重启不失效> 通过修改/etc/sysconfig/network/ifcfg-eth*文件直接配置,服务器重启不失效,建议使用 ...

  5. 使用adb查看CPU和内存

    adb shell ->cat/sys/class/net/wlan0/address 获取Mac地址 abd shell –>cat /proc/cpuinfo 获取CPU信息 adb ...

  6. [PHP]Nginx与PHP的文件上传大小限制

    ---------------------------------------------------------------------------------------------------- ...

  7. springboot配置异常 web页面跳转

    第一步 controller中 package cn.itcast.springboot.controller; import org.springframework.stereotype.Contr ...

  8. github学习心得。哈哈,今天上传了自己的项目!

    使用github托管代码 仓库(Repository) 用来存放项目代码,每个项目对应一个仓库.如果有多个项目了就需要多个仓库 收藏(star) 仓库主页star按钮,意思为收藏项目的人数 复制克隆项 ...

  9. hibernate 工作原理及为什么要用

  10. python3编译安装

    linux下配置安装python3一.首先,官网下载python3的所需版本.wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz ...