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 ...
随机推荐
- 矩阵乘法 NOI2012的一道题
今天,kzj大佬教了我矩阵加速. 让我以这篇随笔表示感谢吧! 这是我刷的一道题:NOI2012 随机数据生成器. 就是普通的矩阵加速,只是要注意的是: 直接用乘法会爆long long,可以参考一下 ...
- [note]树链剖分
树链剖分https://www.luogu.org/problemnew/show/P3384 概念 树链剖分,是一种将树剖分成多条不相交的链的算法,并通过其他的数据结构来维护这些链上的信息. 最简单 ...
- R语言编写乘法表
for(i in 1:9){ for(j in 1:i){ m = j*i cat(i,'*',j,'=',m,' ') } cat('\n') } 1 * 1 = 1 2 * 1 = 2 2 * 2 ...
- vs2008 发布网站时丢失文件问题
右键指定的文件->属性, 将生成操作更改成为"内容"就可以了.
- Kindeditor API
根据map规则删除range中的element或attribute. cmd.remove({ span : '*', div : 'class,border' }); commonNode(ma ...
- mysql高可用研究(二) 主从+MHA+Atlas
关于Atlas的详细介绍请访问:https://github.com/Qihoo360/Atlas/blob/master/README_ZH.md 为什么要使用Atlas?应用程序直连数据库不好吗? ...
- Ubuntu application
inkscape 矢量画图 gimp 类PS gpick 抓色工具 kdenlive 视频编辑 blender 3D Tweaks 外观设置 Krita 绘画工具 Fontforge 字体制作工具 B ...
- 应验log4j.xml时不能找到log4j.dtd
原因分析:log4j.xml中使用log4j的DTD验证其格式的有效性"<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd&quo ...
- 分享知识-快乐自己:Spring整合定时器
前期工作:(引入相关 JAR ) <spring.quartz>1.8.4</spring.quartz> <!--spring 定时--> <depende ...
- Python入门经典练习题
[程序1] 题目:有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? num_list=[]cou=0for i in range(1,5): for j in range( ...