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种 ...
随机推荐
- nginx 服务器 在 centos7 系统下的两种方式
选用系统 Centos7 < 一 > 使用 yum 安装,该方法比较方便,如果不追求版本推荐使用 01, 添加 nginx 储存库 yum -y install epel-releas ...
- go遍历某个文件夹
//遍历文件夹 dir, err := ioutil.ReadDir("./upload_tmp")for _,file := range dir{ logs.Debug(file ...
- unrecognized import path "golang.org/x/net/html"
go run的时候报:unrecognized import path "golang.org/x/net/html" 应该是被墙掉了,自己去github上下载包即可 git cl ...
- dshow采集过程
捕捉静态图片常用的filter是Sample Graber filter,它的用法参考手册.然后将捕捉filter的静态PIN连接到Sample Grabber,再将Sample Grabber连接到 ...
- easyUi弹出window窗口传值与调用父页面的方法,子页面给父页面赋值
<!-- 父页面 --> <!DOCTYPE html PUBLIC "-/W3C/DTD HTML 4.01 Transitional/EN" "ht ...
- 1037C_ Equalize(字符串)
modify 改变 C. Equalize time limit per test 1 second memory limit per test 256 megabytes input standar ...
- ACM__最小生成树之prime
今天做了一道题,根本没想到最小生成树,稀里糊涂的浪费了很多时间,复习一下 转载自https://www.cnblogs.com/zhangming-blog/p/5414514.html Prim算法 ...
- 【BUG记录】记一次游戏越来越卡的BUG
U3D的MOBA项目,测试过程中,10分钟以后,游戏帧率开始缓慢下降,约3-5分钟后,由60帧下降到小于10帧,编辑器模式. 打开profiler,看到CPU占用非常高,每帧都有24K的GC, 时间占 ...
- linux 内存布局以及tlb更新的一些理解
问题: 1.内核线程是否有vma线性区? 2.单线程的一个进程,它修改了自己的页表,是否需要发送ipi来通知其他核更新tlb? 3.普通进程,在32位和64位,对应的线性区的最大地址能到多少? 在64 ...
- How to Pronounce We’ll Contraction
How to Pronounce We’ll Contraction Share Tweet Share Tagged With: WILL Contractions There are severa ...