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 ...
随机推荐
- Centos创建用户
1.创建用户: adduser fish 2.用户设置密码: passwd linuxidc 3.创建文件夹: mkdir fish 4.删除文件夹 rm -rf fish 5.文件夹重命名: mv ...
- python 字典中 重复值去除
tuple_r_dict = lambda _dict: dict(val[::-1] for val in _dict.items()) # Python3.x tuple_r_dict(tuple ...
- leetcode239
class Solution: def maxSlidingWindow(self, nums: 'List[int]', k: int) -> 'List[int]': n = len(num ...
- selenium 3.0变化
Selenium3.0的变化 最大的变化应该是去掉了Selenium RC 了,这是必然的结果.Selenium RC 是Selenium1.0的产物,Selenium2.0以WebDriver为主, ...
- sendmail报错Relaying denied
配置好sendmail后,使用php的mail()发送邮件,出现 SMTP server response: 550 5.7.1 Relaying denied. IP name lookup fai ...
- JUC详解
一.Java多线程 -- JUC包源码分析1 -- CAS/乐观锁 乐观锁其实就是不加锁,用CAS + 循环重试,实现多个线程/多个客户端,并发修改数据的问题 使用AtomicStampedRefer ...
- 1.Ansible安装以及配置
本节内容以Centos7为系统环境进行讲解: 1.安装epel源,方便直接yum安装: wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun ...
- playbook
1 --- - hosts: web-server 3 remote_user: root tasks: - name: stop logstash shell: PID=` $PID &&a ...
- 转:解决AndroidStudio连不上Android设备真机的问题
Android手机开发Android应用的时候,需要连接真机,进行应用软件的真机调试,但是由于诸多原因,可能导致无法与实现连接: 在我们连接了Android设备出现上面这种情况的时候,可以打开设备管理 ...
- 《Spring_Four》第一次作业:团队亮相
part one: 1.队名:Spring_Four 2.团队成员组成:学号/姓名(标记团队组长) 201571030114 李蕾 201571030143 周甜甜 201571030139 张天旭( ...