简单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. eclipse智能提示报错(to avoid the message, disable the...)

    然后这里可能会再报别的错误  我的做法是   再重新将 code recommenders 打开 ********************************** 为什么会出现 这样错误呢 ? 简 ...

  2. 如何画svg路径图

    在画路径图之前,首先得在package.json引入2个依赖 废话不多说,直接上代码 <style> .green { position: absolute; } .blue { posi ...

  3. JavaScript指定日期格式化

    formatDataToString:function (dates, formats) { var o = { "M+": dates.getMonth() + 1, //月份 ...

  4. php获取客户机mac地址

    @exec("arp -a",$array); //执行arp -a命令,结果放到数组$array中 foreach($array as $value){ //匹配结果放到数组$m ...

  5. K2 BPM_北汽新能源业务流程管理信息系统建设思考_全球领先的工作流引擎

    本文由CIO发展中心根据北汽新能源流程与IT总监刘伟霞在“亦庄CIO数字化转型探索——CIO发展中心亦庄分舵2019夏季论坛”活动中演讲整理. 在“亦庄CIO数字化转型探索——CIO发展中心亦庄分舵2 ...

  6. 【vue开发】vue指令Vue.directive使用教程

    1.指令的注册 指令跟组件一样需要注册才能使用,同样有两种方式,一种是全局注册: ? 1 2 3 4 5 Vue.directive('dirName',function(){   //定义指令   ...

  7. 【leetcode】339. Nested List Weight Sum

    原题 Given a nested list of integers, return the sum of all integers in the list weighted by their dep ...

  8. ImportError: No module named yaml

    问题: import yaml ImportError: No module named yaml 解决: wget http://pyyaml.org/download/pyyaml/PyYAML- ...

  9. java之rpc/orm

    Netty线程模型 其中ChannelPiepline的设计模型采用的是Handler组成的责任链模型 blocking I/O 阻塞nonblocking I/O 非阻塞I/O multiplexi ...

  10. BM(Berlekamp-Massey)算法

    线性递推的题目区域赛里还是挺多的,还是有必要学一下 ~ BM(Berlekamp-Massey)算法 ~ 有一个$n$阶线性递推$f$,想要计算$f(m)$,有一种常用的办法是矩阵快速幂,复杂度是$O ...