HDU-1069.MonkeyandBanana(LIS)
本题大意:给出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)的更多相关文章
- HDU 1069 Monkey and Banana(二维偏序LIS的应用)
---恢复内容开始--- Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- HDU 1069 dp最长递增子序列
B - Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I6 ...
- HDU 1069&&HDU 1087 (DP 最长序列之和)
H - Super Jumping! Jumping! Jumping! Time Limit:1000MS Memory Limit:32768KB 64bit IO Format: ...
- 怒刷DP之 HDU 1069
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 1069 Monkey and Banana (DP)
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- 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 ...
- (最大上升子序列)Monkey and Banana -- hdu -- 1069
http://acm.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit:1000MS Memory L ...
- hdu 1069 动规 Monkey and Banana
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- HDU 1069—— Monkey and Banana——————【dp】
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 1069 Monkey and Banana dp 题解
HDU 1069 Monkey and Banana 纵有疾风起 题目大意 一堆科学家研究猩猩的智商,给他M种长方体,每种N个.然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉. 现在给你M种 ...
随机推荐
- taotao商城
(1)写Dao层(大概是sqlMapConfig.xml,application-dao.xml,mapper), 配置顺序和内容,看下图:
- python 如何获取当前文件/文件夹
python 如何获取当前文件/文件夹? 1.获取当前文件的实际路劲: os.path.realpath(__file__) ==> D:\python_test\test_p ...
- Linux 远程登录配置
如果使用FlashFxp的sftp无法登陆,提示SSH 错误: 协商认证模式失败,也同样这样操作 修改你的ssh配置文件 配置文件路径如:/etc/ssh/sshd_config PasswordAu ...
- WPF线性渐变画刷应用之——炫彩线条
效果图: Xaml代码: <Rectangle Width="800" Height="10"> <Rectangle.Fill> &l ...
- 2319__1.5.3 Superprime Rib 特殊的质数肋骨
[Submit][Status][Forum] Description 农民约翰母牛总是产生最好的肋骨. 你能通过农民约翰和美国农业部标记在每根肋骨上的数字认出它们. 农民约翰确定他卖给买方的是真正的 ...
- sourcetree 添加私钥
参考网址: https://www.jianshu.com/p/2a4a39e3704f
- 使用jsoup爬取所有成语
前几天看到有人在博问上求所有成语,想到刚好看了jsoup,就动手实践了一下,提问者给出了网站,一看很简单,就两种页面,一种是包含某个字的成语链接页面,一个是具体的包含某个字的成语的页面 下面是我的代码 ...
- 一个linux内核模块移植到低版本时发生的异常
在3.10的内核版本下,有一个运行稳定的内核模块,移植到suse11的时候,编译正常,运行则直接出现crash: <>[ <>[ 503.347300] Modules lin ...
- 为什么虚拟DOM更优胜一筹
注意: 虚拟DOM只是实现MVVM的一种方案,或者说是视图更新的一种策略.没有虚拟DOM比MVVM更好一说. 我们回顾传统MVC框架,如backbone,它是将某个模板编译成模板函数,需要更新时,是自 ...
- 遍历DOM树,过滤节点
jQuery还提供以下方法来过滤节点. 方法 说明 first() 获取第一个,示例 $('li').last() last() 获取最后一个,示例$('li').last() eq() ...