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 ...
随机推荐
- Mysql数据表去重
查询不重复元素个数 select count(distinct domain) from black_botnet_domian; 查询表中元素个数大于等于2的元素 SELECT goods_id,g ...
- spring boot 常见三十四问
Spring Boot 是微服务中最好的 Java 框架. 我们建议你能够成为一名 Spring Boot 的专家. 问题一 Spring Boot.Spring MVC 和 Spring 有什么区别 ...
- django 过滤器,标签
过滤器: <p>{{ date|date:"Y-m-d" }}</p> {#2018-05-28,date是当前时间#} <p>{{ l|len ...
- 百度分享不支持Https的解决方案--本地化
站点自从开启 https 之后 ,百度分享就不能用了!但是又寻找不到类似百度分享的替代品.. 怎么办呢?要如何解决 百度分享不支持https的问题呢, 跟着博主动动手,让你百度分享仍然能在https下 ...
- 写出良好风格的JS、CSS代码
现在代码的格式都有 eslint.prettier.babel 这些来保证,但是技术手段再高端都不能解决代码可读性的问题. 因为这个只有个人才能解决.但是注意一下事项,可以显著提高代码的可读性.可识别 ...
- 微信小程序 验证码倒计时组件
https://blog.csdn.net/susuzhe123/article/details/80032224
- Django_models下划线__正反查询,对象正反查询
1.我们使用models对数据库进行查询的时候,想去拿到结果的时候有时直接使用".字段",有时是'[0].字段',区别就是我们使用的语句返回的到底是一个对象还是列表: obj=mo ...
- 使用ibatis时 sql中 in 的参数赋值(转)
转:http://www.cnblogs.com/sunzhenchao/archive/2012/12/03/2799365.html 一.问题描述: 1.在使用ibatis执行下面的sql: up ...
- 【python中二叉树的实现】python中二叉树的创建、三种方式递归遍历和非递归遍历
代码如下: # coding=utf-8 class myNode(object): def __init__(self, data=-1, lchild=None, rchild=None): se ...
- 333. Largest BST Subtree节点数最多的bst子树
[抄题]: Given a binary tree, find the largest subtree which is a Binary Search Tree (BST), where large ...