HDU1069:Monkey and Banana(最长上升子序列的应用)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1069
这题挺简单的,给定一个箱子的长宽高,要求啰箱子,但必须保证下面箱子的长和宽必须大于上面的箱子。
一个箱子,有六种情况,排序后,按照最长上升子序列来求解就行了。
代码如下:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int n,tt,dp[];
struct node
{
int x,y,z;
} q[];
int cmp(const void *aa,const void *bb)
{
struct node *a=(struct node *)aa;
struct node *b=(struct node *)bb;
if(a->x!=b->x)
return b->x-a->x;
else if(a->y!=b->y)
return b->y-a->y;
else return b->z-a->z;
}
int main()
{
int K=;
int xx,yy,zz;
int maxx;
while(scanf("%d",&n)!=EOF&&n!=)
{
++K;
tt=;
maxx=-inf;
for(int i=; i<n; i++)
{
scanf("%d%d%d",&xx,&yy,&zz);
q[tt].x=xx;
q[tt].y=yy;
q[tt++].z=zz; q[tt].x=xx;
q[tt].y=zz;
q[tt++].z=yy; q[tt].x=yy;
q[tt].y=xx;
q[tt++].z=zz; q[tt].x=yy;
q[tt].y=zz;
q[tt++].z=xx; q[tt].x=zz;
q[tt].y=xx;
q[tt++].z=yy; q[tt].x=zz;
q[tt].y=yy;
q[tt++].z=xx;
}
qsort(q+,tt+,sizeof(q[]),cmp);
memset(dp,,sizeof(dp));
dp[]=q[].z;
maxx=max(maxx,q[].z);
for(int i=;i<tt;i++)
{
for(int j=;j<i;j++)
{
if(q[i].x<q[j].x&&q[i].y<q[j].y)
{
dp[i]=max(dp[i],dp[j]);
}
}
dp[i]=dp[i]+q[i].z;
maxx=max(maxx,dp[i]);
}
printf("Case %d: maximum height = %d\n",K,maxx);
}
return ;
}
HDU1069:Monkey and Banana(最长上升子序列的应用)的更多相关文章
- 杭电oj 1069 Monkey and Banana 最长递增子序列
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU 1069 Monkey and Banana(最长递减子序列)
题目链接 题意:摞长方体,给定长方体的长宽高,个数无限制,可随意翻转,要求下面的长方体的长和宽都大于上面的,都不能相等,问最多能摞多高. 题解:个数无限,其实每种形态最多就用一次,把每种形态都单独算一 ...
- HDU1069 Monkey and Banana
HDU1069 Monkey and Banana 题目大意 给定 n 种盒子, 每种盒子无限多个, 需要叠起来, 在上面的盒子的长和宽必须严格小于下面盒子的长和宽, 求最高的高度. 思路 对于每个方 ...
- kuangbin专题十二 HDU1069 Monkey and Banana (dp)
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU1069 Monkey and Banana —— DP
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS ...
- HDU1069:Monkey and Banana(DP+贪心)
Problem Description A group of researchers are designing an experiment to test the IQ of a monkey. T ...
- HDU-1069 Monkey and Banana DAG上的动态规划
题目链接:https://cn.vjudge.net/problem/HDU-1069 题意 给出n种箱子的长宽高 现要搭出最高的箱子塔,使每个箱子的长宽严格小于底下的箱子的长宽,每种箱子数量不限 问 ...
- HDU1069 - Monkey and Banana【dp】
题目大意 给定箱子种类数量n,及对应长宽高,每个箱子数量无限,求其能叠起来的最大高度是多少(上面箱子的长宽严格小于下面箱子) 思路 首先由于每种箱子有无穷个,而不仅可以横着放,还可以竖着放,歪着放.. ...
- HDU1069 Monkey and Banana(dp)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 题意:给定n种类型的长方体,每个类型长方体无数个,要求长方体叠放在一起,且上面的长方体接触面积要小于 ...
- hdu1069 Monkey and Banana LIS
#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #inc ...
随机推荐
- winform 查看远程服务器上的文件
解决方案: 1. 在目标服务器上发布webservice,实现文件下载的方法. using System; using System.Collections.Generic; using System ...
- (译)Getting Started——1.2.2 Desinging a User Interface(设计用户界面)
用户需要以最简单的方式与应用界面进行交互.应该从用户的角度出发设计页面,使得界面更高效.简捷和直接. storyboard以图形化的方式帮助你设计和实现界面.在设计和实现界面的过程中,你 ...
- HBase学习笔记——概念及原理
1.什么是HBase HBase – Hadoop Database,是一个高可靠性.高性能.面向列.可伸缩的分布式存储系统,利用HBase技术可在廉价PC Server上搭建起大规模结构化存储集群. ...
- linux apache Tomcat配置SSL(https)步骤
https简介 它是由Netscape开发并内置于其浏览器中,用于对数据进行压缩和解压操作,并返回网络上传送回的结果.HTTPS实际上应用了Netscape的安全套接字层(SSL)作为HTTP应用层的 ...
- 将字符“12345”转换成long型
将字符“12345”转换成long型 解答: String s=”12345″; long num=Long.valueOf(s).longValue();
- HashMap与TreeMap的区别?
HashMap与TreeMap的区别? 解答:HashMap通过hashcode对其内容进行快速查找,而TreeMap中所有的元素都保持着某种固定的顺序,如果你需要得到一个有序的结果你就应该使用Tre ...
- .NET中二进制图片的存储与读取
判断HttpContext是否为空: string configPath = "img/defaultPhoto.png"; if (HttpContext.Current != ...
- openwrt U盘启动
参考链接: http://m.blog.csdn.net/blog/zcynical/44892785
- Spring MVC multipart/form-data Controller 400
问题很简单是解析器定义问题 SpringMVC默认解析器 <bean id="multipartResolver" class="org.springframewo ...
- hdu 1754 I Hate It(线段树之 单点更新+区间最值)
I Hate It Time Limit: 90 ...