HDOJ(1069)最长下降子序列
每个箱子可有3种叠加方式,所以有3*n个箱子。将箱子按长度由大到小排序,有求箱子按宽度的最长下降子序列的高度之和即可。
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define MAX(a,b) (a>b)?a:b
#define MIN(a,b) (a>b)?b:a
const int SIZE=+;//尽量大一些;
struct node{
int l;
int w;
int h;
};
node box[*SIZE]; bool comp(node no1, node no2)
{
return no1.l > no2.l;
}
int main()
{
int n;
int t=;
while(scanf("%d",&n)!=EOF&&n!=)
{
for(int i=;i<n;i++)
{
int x,y,z;
scanf("%d %d %d",&x,&y,&z);
box[i*+].h=x;box[i*+].l=MAX(y,z);box[i*+].w=MIN(y,z);
box[i*+].h=y;box[i*+].l=MAX(x,z);box[i*+].w=MIN(x,z);
box[i*+].h=z;box[i*+].l=MAX(y,x);box[i*+].w=MIN(y,x);
} sort(box,box+*n,comp); int ans=-;
int h[SIZE];
memset(h,,sizeof(h));
for(int i=;i<*n;i++)
{
h[i]=box[i].h;
for(int j=;j<i;j++)
{
if(box[i].w<box[j].w&&box[i].l<box[j].l)
{
h[i]=MAX(h[j]+box[i].h,h[i]);
}
}
ans=MAX(h[i],ans);
}
printf("Case %d: maximum height = %d\n",++t,ans);
} return ;
}
HDOJ(1069)最长下降子序列的更多相关文章
- 最长下降子序列O(n^2)及O(n*log(n))解法
求最长下降子序列和LIS基本思路是完全一样的,都是很经典的DP题目. 问题大都类似于 有一个序列 a1,a2,a3...ak..an,求其最长下降子序列(或者求其最长不下降子序列)的长度. 以最长下降 ...
- BUY LOW, BUY LOWER_最长下降子序列
Description The advice to "buy low" is half the formula to success in the bovine stock mar ...
- 【最长下降子序列】【动态规划】【二分】XMU 1041 Sequence
题目链接: http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1041 题目大意: 一个二维平面,上面n(n<=1 000 000)个点.问至少选 ...
- 【最长下降子序列的长度和个数】 poj 1952
转自http://blog.csdn.net/zhang360896270/article/details/6701589 这题要求最长下降子序列的长度和个数,我们可以增加数组maxlen[size] ...
- POJ-1887 Testing the CATCHER(dp,最长下降子序列)
Testing the CATCHER Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16515 Accepted: 6082 ...
- ZZNU 1719(最长上升子序列+最长下降子序列)
先吐血一发,噗! 再吐血一次,啊啊啊啊! 好吧,做了那么多次最长上升子序列,看这题看了半天才发现还有最长下降子序列,呵呵哒! AC代码: #include<stdio.h>//老恶心#in ...
- 九度OJ 1112:拦截导弹 (DP、最长下降子序列)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3124 解决:1525 题目描述: 某国为了防御敌国的导弹袭击,开发出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能 ...
- hdu1160简单dp最长下降子序列
/* 简单dp,要记录顺序 解:先排序,然后是一个最长下降子序列 ,中间需记录顺序 dp[i]=Max(dp[i],dp[j]+1); */ #include<stdio.h> #incl ...
- POJ 1836 Alignment(DP max(最长上升子序列 + 最长下降子序列))
Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 14486 Accepted: 4695 Descri ...
随机推荐
- How to avoid Over-fitting using Regularization?
http://www.mit.edu/~9.520/scribe-notes/cl7.pdf https://en.wikipedia.org/wiki/Bayesian_interpretation ...
- What happens when we continue stacking deeper layers on a “plain” convolutional neural network?
http://cs231n.stanford.edu/slides/2017/cs231n_2017_lecture9.pdf The deeper model performs worse, but ...
- Virtualbox报错------> '/etc/init.d/vboxdrv setup'
Ubuntu下VirtualBox本来可以很好地用的,今天早上一来就报错了,--提示如下内容: ---------------------------------------------------- ...
- jauery table
$("#tableData tr:gt(0)").each(function() { }//橘色部分是查找id为tableData的DataTable里面除第一行以外的行
- python学习-4-类的使用
class Animal: def __init__(self, name): # Constructor of the class self.name = name def talk(self): ...
- LeetCode:盛最多水的容器【11】
LeetCode:盛最多水的容器[11] 题目描述 给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 ...
- java 类中定义接口的调用方法
public class Human { public interface MyAction { public void getPower(); } } public class Test{ publ ...
- static_class
<?php class MyObject { public static $myStaticVar = 0; function myMethod() { self::$myStaticVar + ...
- Hive与Hbase关系整合
近期工作用到了Hive与Hbase的关系整合,虽然从网上参考了很多的资料,但是大多数讲的都不是很细,于是决定将这块知识点好好总结一下供大家分享,共同掌握! 本篇文章在具体介绍Hive与Hbase整合之 ...
- server.xml笔记
本文总结自: http://www.importnew.com/26156.html 核心元素: 顶层元素: server service 连接器: connector 容器: engine > ...