简单DP。

  题意:给出若干种长方体,如果摆放时一个长方体的长和宽小于另一个的长宽,那么它可以放在另一个的上面,问最高能放多少高度。每种长方体的个数都是无限的。

  做法:因为每种个数都是无限,那么每种按照x,y,z分别重新排列可以得到6种长方体。现在用dp[i]表示选到第i个且第i个必须使用的最大高度,那么转移是从1~i-1中的dp中选一个能放在i的前面的最大值放在i的前面,再加上第i个的高,就得到了dp[i](如果一个都不能放在i的前面,那就只放i即可)。然后最终答案是dp[1]~dp[n]的最大值。

  注意点是在dp前必须按照(x,y)先排序,这样可以保证第i个能够放在它前面的一定在1~i-1中(后面的一定x或y比它大)。

  代码如下:

 #include <stdio.h>
#include <algorithm>
#include <string.h>
#include <map>
using namespace std;
const int N = 1e7 + ;
const int inf = 0x3f3f3f3f; struct node
{
int x,y,z;
bool operator < (const node & temp) const
{
return x == temp.x ? y < temp.y : x < temp.x;
}
}p[]; int dp[]; int main()
{
int kase = ;
int n;
while(scanf("%d",&n) == && n)
{
for(int i=;i<=n;i++)
{
scanf("%d%d%d",&p[i].x,&p[i].y,&p[i].z);
p[i+n] = (node){p[i].x,p[i].z,p[i].y};
p[i+*n] = (node){p[i].y,p[i].x,p[i].z};
p[i+*n] = (node){p[i].y,p[i].z,p[i].x};
p[i+*n] = (node){p[i].z,p[i].x,p[i].y};
p[i+*n] = (node){p[i].z,p[i].y,p[i].x};
}
sort(p+,p++*n);
memset(dp,,sizeof dp);
for(int i=;i<=*n;i++)
{
dp[i] = p[i].z;
for(int j=;j<i;j++)
{
if(p[j].x < p[i].x && p[j].y < p[i].y && dp[j] + p[i].z > dp[i]) dp[i] = dp[j] + p[i].z;
}
}
printf("Case %d: maximum height = %d\n",kase++,*max_element(dp+,dp++*n));
}
}

  

  顺便考虑一个问题,如果要求的是最大能放几个长方体,那就是LIS的问题了。

HDU 1069 Monkey and Banana ——(DP)的更多相关文章

  1. HDU 1069 Monkey and Banana (dp)

    题目链接 Problem Description A group of researchers are designing an experiment to test the IQ of a monk ...

  2. HDU 1069 Monkey and Banana(动态规划)

    Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...

  3. HDU 1069 Monkey and Banana(DP——最大递减子序列)

    题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=1069 题意描述: 给n块砖,给出其长,宽和高 问将这n块砖,怎样叠放使得满足以下条件使得 ...

  4. HDU 1069 Monkey and Banana (动态规划)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 简单记录一下 思路:把长方体的各种摆法都存到数组里面,然后按照长宽排序,再dp即可 转移方程 d ...

  5. HDU 1069 Monkey and Banana(转换成LIS,做法很值得学习)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS (Java ...

  6. HDU 1069:Monkey and Banana(DP)

    Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  7. HDU 1069 Monkey and Banana(二维偏序LIS的应用)

    ---恢复内容开始--- Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  8. HDU 1069 Monkey and Banana (动态规划、上升子序列最大和)

    Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  9. HDU 1069 Monkey and Banana 基础DP

    题目链接:Monkey and Banana 大意:给出n种箱子的长宽高.每种不限个数.可以堆叠.询问可以达到的最高高度是多少. 要求两个箱子堆叠的时候叠加的面.上面的面的两维长度都严格小于下面的. ...

随机推荐

  1. c#入门学习笔记

    Hello World //打印语句 Console.WriteLine("Hello World"); //暂停 Console.ReadKey(); 数据类型 1.值类型 by ...

  2. JavaBean 详细

    一.什么是JavaBean? JavaBean是一个遵循特定写法的Java类,它通常具有如下特点: 这个Java类必须具有一个无参的构造函数 属性必须私有化. 私有化的属性必须通过public类型的方 ...

  3. py datetime

    python datetime模块strptime/strptime format常见格式命令- [python]2011-12-23   版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本 ...

  4. 五、HashMap的使用 及其源码解析

    HashMap的底层实现原理?领接表(数组+链表)hash表数组+链表+红黑树 链表:查找慢 插入 删除快红黑树:查找快 插入 删除慢 HashMap是线程安全的吗?不是线程安全的 在什么情况下 ,是 ...

  5. CRM和C4C里的组织架构 - Organizational Structure

    CRM(WebClient UI) CRM(SAP GUI,事务码PPOMA_CRM) C4C 以列表方式显示: 以图形方式显示: UI模型: /SAP_BYD_APPLICATION_UI/mom/ ...

  6. 【leetcode】637. Average of Levels in Binary Tree

    原题 Given a non-empty binary tree, return the average value of the nodes on each level in the form of ...

  7. hadoop相关随记

    1.用来查询集群上启动的job,并杀掉DumpTrack状态的job: yarn application -list|grep DumpTrack|awk '{print $1}' | xargs y ...

  8. Linux磁盘管理——swap分区

    转自:Linux Swap交换分区设置 对swap分区的误解 一种流行的.以讹传讹的说法是,安装Linux系统时,交换分区swap的大小应该是内存的两倍.也就是说,如果内存是2G,那么就应该分出4G的 ...

  9. Linux网络管理——ifconfig、route

    Linux识别到的网络设备 eth#   eth0   eth1 以太网卡 wifi#   wifi0  wifi1 无线网卡 ppp#   ppp0  ppp1 拨号连接 lo     本地环回网卡 ...

  10. Linux赋予root权限

    按照帖子都一一尝试了下 https://blog.csdn.net/yajie_china/article/details/80636783 首先增加用户和给新用户创建密码,都不用说 用useradd ...