简单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. Asp.Net Mvc项目添加WebApi

    1.添加一个WebApi 空项目 2.删除WebApi项目下的 Global.asax 文件,因为我们要把WebApi项目整合到Mvc项目中去,全局只需要一个Global 3.修改 WebApi 项目 ...

  2. ASP.NET Core 入门(3)(单元测试Xunit及Shouldly的使用)

    一.本篇简单介绍下在ASP.NET Core项目如何使用单元测试,例子是使用VS自带的Xunit来测试Web API接口,加上一款开源的断言工具Shouldly,方便写出更简洁.可读行更好的测试代码. ...

  3. Node +FastDFS 实现文件的上传下载

    npm install fastdfsl-client //--------------------------------配置文件---------------------------------- ...

  4. spring data 入门

    提出问题 我是Sping Data,是程序员的春天,因为我提供很多接口给开发人员, 减少程序员重复的写CRUD和分页等方法,你们也可以叫我春D,或者春帝,因为我很酷 解决问题 在Spring Data ...

  5. swoole httpserver学习

    文件 HttpServer.php <?php /** * Created by PhpStorm. * User: mac * Date: 2019/9/13 * Time: 21:00 */ ...

  6. Docker安装nginx,把nginx.conf放入指定位置

    拉取镜像 docker pull nginx 创建目录 创建一个目录用来存放文件,方便我们进行修改 mkdir -p /everything/nginx/conf /everything/nginx/ ...

  7. tcp关闭连接:挥手讨论

    讨论焦点: 如果client发送FIN后,服务器端未返回完成的数据(缓存区中)还执行返回吗? 参考文档:https://download.csdn.net/download/u013547552/10 ...

  8. 阿里P7浅谈SpringMVC

    一.前言 既然是浅谈 SpringMVC,那么我们就先从基础说起,本章节主要讲解以下内容: 1.三层结构介绍 2.MVC 设计模式介绍 3.SpringMVC 介绍 4.入门程序的实现 注:介绍方面的 ...

  9. goroutine的设计与实现

    goroutine背后的系统知识 http://www.sizeofvoid.net/goroutine-under-the-hood/ 下周写完

  10. CSRF(cross-site request forgery )跨站请求攻击

    CSRF(cross-site request forgery )跨站请求伪造,攻击者盗用了你的身份,以你的名义发送恶意请求,对服务器来说这个请求是完全合法的,但是却完成了攻击者所期望的一个操作,通过 ...