HDU 1069 Monkey and Banana dp 题解
HDU 1069 Monkey and Banana
纵有疾风起
题目大意
一堆科学家研究猩猩的智商,给他M种长方体,每种N个。然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉。
现在给你M种长方体,计算,最高能堆多高。要求位于上面的长方体的长要大于(注意不是大于等于)下面长方体的长,上面长方体的宽大于下面长方体的宽。
输入输出
开始一个数n,表示有多少种木块,木块的数量无限,然后接下来的n行,每行3个数,是木块的长宽高三个参量
输出使用这些在满足条件的情况下能够摆放的最大高度
解题思路
首先,我们严格令长>宽,可以想到一种木块有3种摆放方式,长、宽、高分别在下面。
对于摆放种类,我们可以使用dp动态规划来进行,看了其他博主写的博客,这个题和求最长递增子序列差不多(反过来想的,就是把塔给倒过来进行构造)。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=200;
struct node{
int l, w, h;
bool friend operator < (node a, node b)
{
if(a.h==b.h)
return a.w > b.w;
else
return a.l > b.l;
}
}a[maxn];
int dp[maxn];
int main()
{
int t=1, n;
while(scanf("%d", &n) && n!=0)
{
int len = 0, x, y, z;
for(int i=0; i<n; i++)
{
scanf("%d%d%d", &x, &y, &z);
a[len].h=x; a[len].l= y>z? y:z; a[len++].w= y>z? z:y;
a[len].h=y; a[len].l= x>z? x:z; a[len++].w= x>z? z:x;
a[len].h=z; a[len].l= x>y? x:y; a[len++].w= x>y? y:x;
}
sort(a, a+len);//排序是关键,最长递增子序列不用排序
for(int i=0; i<len; i++)
dp[i]=a[i].h; //初始值是每一个长方体的高
int max_h, ans=0;
for(int i=1; i<len; i++)
{
max_h=0;
for(int j=0; j<i; j++)
{
if(a[j].l > a[i].l && a[j].w > a[i].w)
{
max_h = max_h > dp[j] ? max_h : dp[j];
}
}
dp[i]=a[i].h+max_h;
ans=max(ans, dp[i]);
}
printf("Case %d: maximum height = %d\n", t++, ans);
}
return 0;
}
HDU 1069 Monkey and Banana dp 题解的更多相关文章
- 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 长方体堆放问题)
Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...
- HDU 1069 Monkey and Banana DP LIS变形题
http://acm.hdu.edu.cn/showproblem.php?pid=1069 意思就是给定n种箱子,每种箱子都有无限个,每种箱子都是有三个参数(x, y, z)来确定. 你可以选任意两 ...
- HDU 1069 Monkey and Banana DP LIS
http://acm.hdu.edu.cn/showproblem.php?pid=1069 题目大意 一群研究员在研究猴子的智商(T T禽兽啊,欺负猴子!!!),他们决定在房顶放一串香蕉,并且给猴子 ...
- HDU 1069 monkey an banana DP LIS
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uDescription 一组研究人员正在 ...
- 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 ...
- HDU 1069 Monkey and Banana(转换成LIS,做法很值得学习)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS (Java ...
- 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
题目链接:Monkey and Banana 大意:给出n种箱子的长宽高.每种不限个数.可以堆叠.询问可以达到的最高高度是多少. 要求两个箱子堆叠的时候叠加的面.上面的面的两维长度都严格小于下面的. ...
随机推荐
- php内置函数分析之strpos()
PHP_FUNCTION(strpos) { zval *needle; zend_string *haystack; char *found = NULL; ]; zend_long offset ...
- 【串线篇】spring boot嵌入式Servlet容器自动配置原理
EmbeddedServletContainerAutoConfiguration:嵌入式的Servlet容器自动配置? @AutoConfigureOrder(Ordered.HIGHEST_PREC ...
- uoj280 【UTR #2】题目难度提升 堆维护中位数+set
题目传送门 http://uoj.ac/problem/280 题解 这道题很妙啊. 这种题目如果给予选手足够的时间,每一个选手应该都能做出来. 大概就是核心思路看上去很简单,但是想要推出来并不简单. ...
- Git版本控制工具初识
Git使用教程 0 Git下载安装 下载网址:https://www.git-scm.com/download/ 安装时,一路next就可以了,如果遇到下载很慢时,可以选择换个浏览器试试,实在不行就找 ...
- SpringBoot框架(1)--入门篇
什么是SpringBoot? Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程. 特征 创建独立的Spring应用程序 直接嵌 ...
- HTML中的表单<form>标签
一.HTML表单 HTML 表单用于搜集不同类型的用户输入. HTML 表单包含表单元素,表单元素指的是不同类型的 input 元素.复选框.单选按钮.提交按钮等等. 关于表单的更多内容可以参考htt ...
- rk3328设备树学习
一.用到的rk3328好像使用了设备树 设备树我知道的有三种文件类型,dtbs是通过指令make dtbs编译的二进制文件,供内核使用. 基于同样的软件分层设计的思想,由于一个SoC可能对应多个mac ...
- apiCloud通过ajax获取数据
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name ...
- 【PowerOJ1754&网络流24题】负载平衡问题(费用流)
题意: 思路: [问题分析] 转化为供求平衡问题,用最小费用最大流解决. [建模方法] 首先求出所有仓库存货量平均值,设第i个仓库的盈余量为A[i],A[i] = 第i个仓库原有存货量 - 平均存货量 ...
- [BZOJ4552]:[Tjoi2016&Heoi2016]排序(桶排序)
题目传送门 题目描述 在2016年,佳媛姐姐喜欢上了数字序列. 因而她经常研究关于序列的一些奇奇怪怪的问题,现在她在研究一个难题,需要你来帮助她. 这个难题是这样子的:给出一个1到n的全排列,现在对这 ...