随手练——ZOJ 1093 Monkey and Banana(动态规划)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=93
一堆科学家研究猩猩的智商,给他M种长方体,每种N个。
然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉。
现在给你M种长方体,计算,最高能堆多高。
要求位于上面的长方体的长要大于(注意不是大于等于)下面长方体的长,上面长方体的宽大于下面长方体的宽。
解题:
1、一个长方体,可以有6种不同的摆法。长宽排序,就可以只存下来三种,需要的是高的唯一性。
2、将所有长方体按底面积升序排序。
3、第 i 个长方体的最大值 = 前i个(0到i - 1)长方体所能构成的最大高度 + 自己的高度。(升序是为了保证前 i 个长方体底面积一定≤第 i 个,是有可能摆在第i个上面的。)
转移方程:
4、遍历一遍dp数组,得到最大值。
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
class block {
public:
int length, width, height;
block() {};
block(int x, int y, int z) {
length = x; width = y; height = z;
}
//按底面积大小升序排序
bool operator <(block b) const {
return length * width < b.width* b.length;
}
}cube[];
];
bool check(block under, block upper) {
if (under.length > upper.length && under.width > upper.width) return true;
return false;
}
int main() {
;
while (cin >> n) {
)break;
; i < n; i++) {
int l, w, h;
scanf("%d%d%d", &l, &w, &h);
//长方体的height,length,width分别作高
cube[i * + ] = block(l > w ? l : w, l > w ? w : l, h);
cube[i * + ] = block(w > h ? w : h, w > h ? h : w, l);
cube[i * + ] = block(h > l ? h : l, l > h ? h : l, w);
}
sort(cube, cube + n * );
dp[] = cube[].height;
; i < n * ; i++) {
;
; j < i; j++) {
if (cube[i].length > cube[j].length && cube[i].width > cube[j].width) {
temp = dp[j] > temp ? dp[j] : temp;//找前i个长方体的最大值
}
}
dp[i] = cube[i].height + temp;
}
;
; i < n * ; i++) {
max = dp[i] > max ? dp[i] : max;
}
cout << "Case " << k++ << ": maximum height = " << max << endl;
}
;
}
随手练——ZOJ 1093 Monkey and Banana(动态规划)的更多相关文章
- 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 ...
- ZOJ 1093 Monkey and Banana (LIS)解题报告
ZOJ 1093 Monkey and Banana (LIS)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- HDU——Monkey and Banana 动态规划
Monkey and Banana Time Limit:2000 ...
- Monkey and Banana 题解(动态规划)
Monkey and Banana 简单的动态规划 1.注: 本人第一篇博客,有啥不足还请多多包涵,有好的建议请指出.你以为有人读你博客,还给你提意见. 2.原题 Background: A grou ...
- HDU 1069 Monkey and Banana(动态规划)
Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...
- Monkey and Banana(HDU 1069 动态规划)
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1069 Monkey and Banana (动态规划、上升子序列最大和)
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- hdu1069Monkey and Banana(动态规划)
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1069 Monkey and Banana dp 题解
HDU 1069 Monkey and Banana 纵有疾风起 题目大意 一堆科学家研究猩猩的智商,给他M种长方体,每种N个.然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉. 现在给你M种 ...
随机推荐
- PCA算法学习(Matlab实现)
PCA(主成分分析)算法,主要用于数据降维,保留了数据集中对方差贡献最大的若干个特征来达到简化数据集的目的. 实现数据降维的步骤: 1.将原始数据中的每一个样本用向量表示,把所有样本组合起来构成一个矩 ...
- Java基础知识你知道多少?
Java虚拟机基础知识你知道多少? Java并发基础知识你知道多少? Java数据结构基础知识你知道多少? java序列化与反序列化 https://github.com/zhantong/inter ...
- python学习之老男孩python全栈第九期_day003作业
1. 有变量name = "aleX leNb" 完成如下操作:(1) 移除 name 变量对应的值两边的空格,并输出处理结果name = ' aleX leNb 'print(n ...
- js-对象深度克隆方法
学习收藏. 1.来自http://www.cnblogs.com/yxz-turing/p/4784861.html function cloneObj(obj){ var str, newobj = ...
- List中Add()与AddAll()的区别
我们在开发过程中经常会使用到List<Object> list=new ArrrayList<>(); 这个集合,Object 也可以是String.Integer等. 当我们 ...
- <Android 基础(三十一)> ObjectAnimator
简介 ObjectAnimator,是ValueAnimator的子类,支持利用目标视图的属性来实现动画效果.构造ObjectAnimator的时候,将会提取对应的参数来定义动画对象和对象属性.合适的 ...
- ArcGIS三种方式打断相交线------Planarize Lines工具
1. 只有一个layer图层时,我们只需要选择”Planarize Lines“工具即可. (1)选择工具栏”Customize“选项: (2)选择Customize工具栏中的”Toolbars“选项 ...
- jsp隐式对象
隐式对象使用位置 隐式对象在转译为Servlet后,是_jspService()中的局部变量.隐式对象只能在<%与%>之间,或<%=与%>之间直接使用. 无法在<%!与% ...
- Hive 锁 lock
Hive + zookeeper 可以支持锁功能 锁有两种:共享锁.独占锁,Hive开启并发功能的时候自动开启锁功能 1)查询操作使用共享锁,共享锁是可以多重.并发使用的 2)修改表操作使用独占锁,它 ...
- go语言练习:文件哈希
package main import ( "crypto/sha256" "encoding/hex" "fmt" "io&qu ...