hdu 1069 Monkey and Banana 【动态规划】
题意:研究人员要测试猴子的IQ,将香蕉挂到一定高度,给猴子一些不同大小的箱子,箱子数量不限,让猩猩通过叠长方体来够到香蕉。 现在给你N种长方体, 要求:位于上面的长方体的长和宽 要小于 下面长方体的长和宽。

思路:对于一种长方体,长宽高(a,b,c)有6总不同的组成方式{(a,b,c),(a,c,b),(b,a,c),(b,c,a),(c,a,b),(c,b,a) },对所有组成方式的长方体从小到大排序,比较满足长1<长2,宽1<宽2,的最大高度。
dp[i]: 表示第i个盒子的高 + 前i-1个盒子在满足(x1<x2,y1<y2)的情况下可以组成的最大的高度
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int Max = 200+10;
//dp[i]:表示第i个盒子的高+前i-1个盒子在满足(x1<x2,y1<y2)的情况下可以组成的最大的高
int dp[Max];
struct node{
int x,y,z;
};
node no[Max];
int cmp(node a,node b)
{
if(a.x==b.x) return a.y<b.y;
else return a.x<b.x;
}
int main()
{
int n,x,y,z;
int Case =1;
while(cin>>n)
{
if(n==0) break;
int cnt = 0;
for(int i=0;i<n;i++)
{
cin>> x >> y >>z;
no[cnt].x = x,no[cnt].y=y,no[cnt++].z=z;
no[cnt].x = x,no[cnt].y=z,no[cnt++].z=y;
no[cnt].x = y,no[cnt].y=x,no[cnt++].z=z;
no[cnt].x = y,no[cnt].y=z,no[cnt++].z=x;
no[cnt].x = z,no[cnt].y=x,no[cnt++].z=y;
no[cnt].x = z,no[cnt].y=y,no[cnt++].z=x;
}
sort(no,no+cnt,cmp);
dp[0]=no[0].z;
int maxh;
for(int i=1;i<cnt;i++)
{
maxh=0;
for(int j=0;j<i;j++)
{
if(no[j].x<no[i].x&&no[j].y<no[i].y)
maxh = max(maxh,dp[j]);;
}
dp[i] = no[i].z+maxh;
}
maxh=0;
for(int i=0;i<cnt;i++)
if(dp[i]>maxh) maxh = dp[i];
printf("Case %d: maximum height = %d\n",Case++,maxh);
}
return 0;
}
hdu 1069 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 ...
- HDU 1069 Monkey and Banana dp 题解
HDU 1069 Monkey and Banana 纵有疾风起 题目大意 一堆科学家研究猩猩的智商,给他M种长方体,每种N个.然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉. 现在给你M种 ...
- 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(动态规划)
Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...
- HDU 1069 Monkey and Banana (动态规划、上升子序列最大和)
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1069 Monkey and Banana(二维偏序LIS的应用)
---恢复内容开始--- Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- 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 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- hdu 1069 Monkey 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 长方体堆放问题)
Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...
随机推荐
- Spring 了解Bean的一生(生命周期)
转载 https://blog.csdn.net/w_linux/article/details/80086950 该篇博客就来了解IoC容器下Bean的一生吧,也可以理解为bean的生命周期. ## ...
- [持续交付实践] pipeline使用:快速入门
什么是pipeline 先介绍下什么是Jenkins 2.0,Jenkins 2.0的精髓是Pipeline as Code,是帮助Jenkins实现CI到CD转变的重要角色.什么是Pipeline, ...
- kubernets网络模式
参考:https://www.kubernetes.org.cn/2059.html
- Android向系统日历中添加日程事件
转自Android向系统日历中添加日程事件 总结 在项目开发中,我们有预约提醒.定时提醒需求时,可以使用系统日历来辅助提醒: 通过向系统日历中写入事件.设置提醒方式(闹钟),实现到时间自动提醒的功能: ...
- 深度学习原理与框架-CNN在文本分类的应用 1.tf.nn.embedding_lookup(根据索引数据从数据中取出数据) 2.saver.restore(加载sess参数)
1. tf.nn.embedding_lookup(W, X) W的维度为[len(vocabulary_list), 128], X的维度为[?, 8],组合后的维度为[?, 8, 128] 代码说 ...
- python中os模块
os 模块 操作系统模块,该模块主要处理与操作系统相关的操作 最常用是文件操作:打开.读取 import os os.getcwd() #获取当前执行文件夹路径 os.chdir('dirnam ...
- html背景图星际导航图练习
html <body> <div class="box1"> <div></div> ...
- python 常用模块(一): os模块,序列化模块(json模块 pickle模块 )
1.os模块 2.序列化模块:(1)json模块 和 pickle模块 一.os模块 os.path.abspath: (1)把路径中不符合规范的/改成操作系统默认的格式 import os path ...
- phpcms的一些问题 乱码,安装
一.乱码:我这的网站出现的乱码情况:后台栏目名乱码,迁站后更新缓存,再更新栏目,内容,前台都乱码. 找了半天原因,经过本地测试,没问题,一上线就出现问题,不同点就是线上的数据库版本是mysql5.5, ...
- python note 04 list的应用及元组
1,昨日内容 ascii:字母,数字,特殊字符:1个字节,8位 Unicode:16位 两个字节 升级 32 位 四个字节 utf-8:最少一个字节 8位表示. 英文字母 8位 1个字节 欧洲16位, ...