每个箱子可有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)最长下降子序列的更多相关文章

  1. 最长下降子序列O(n^2)及O(n*log(n))解法

    求最长下降子序列和LIS基本思路是完全一样的,都是很经典的DP题目. 问题大都类似于 有一个序列 a1,a2,a3...ak..an,求其最长下降子序列(或者求其最长不下降子序列)的长度. 以最长下降 ...

  2. BUY LOW, BUY LOWER_最长下降子序列

    Description The advice to "buy low" is half the formula to success in the bovine stock mar ...

  3. 【最长下降子序列】【动态规划】【二分】XMU 1041 Sequence

    题目链接: http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1041 题目大意: 一个二维平面,上面n(n<=1 000 000)个点.问至少选 ...

  4. 【最长下降子序列的长度和个数】 poj 1952

    转自http://blog.csdn.net/zhang360896270/article/details/6701589 这题要求最长下降子序列的长度和个数,我们可以增加数组maxlen[size] ...

  5. POJ-1887 Testing the CATCHER(dp,最长下降子序列)

    Testing the CATCHER Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16515 Accepted: 6082 ...

  6. ZZNU 1719(最长上升子序列+最长下降子序列)

    先吐血一发,噗! 再吐血一次,啊啊啊啊! 好吧,做了那么多次最长上升子序列,看这题看了半天才发现还有最长下降子序列,呵呵哒! AC代码: #include<stdio.h>//老恶心#in ...

  7. 九度OJ 1112:拦截导弹 (DP、最长下降子序列)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3124 解决:1525 题目描述: 某国为了防御敌国的导弹袭击,开发出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能 ...

  8. hdu1160简单dp最长下降子序列

    /* 简单dp,要记录顺序 解:先排序,然后是一个最长下降子序列 ,中间需记录顺序 dp[i]=Max(dp[i],dp[j]+1); */ #include<stdio.h> #incl ...

  9. POJ 1836 Alignment(DP max(最长上升子序列 + 最长下降子序列))

    Alignment Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 14486   Accepted: 4695 Descri ...

随机推荐

  1. 基于flask的web微信

    web微信 1.扫码获取头像 当你打开web微信的时候,因为http是无状态的,web微信如何实时的获取用户的扫码动作? 那么这里用到的是长轮询的方式. from flask import Flask ...

  2. MyEclipse2014新增bug,尝鲜的朋友需注意NotFoundException: org.springframework.web.context.ContextLoaderListener

    事实上标题后面加上这个异常信息并不合适,可是为了方便和我遇到相同问题的童鞋搜到这篇文章.我不得不这样写啦. 这个异常和你的程序没有关系,假设你没有忘记增加spring Jar包的话,这是fucking ...

  3. VIM YCM 插件安装问题记录

    参考:https://github.com/yangyangwithgnu/use_vim_as_ide https://github.com/Valloric/YouCompleteMe 根据 ht ...

  4. 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 ...

  5. linux 中sort命令 按照指定列排序

    sort怎样按指定的列排序0000 27189 41925425065f 15 419254250663 7 419254250675 5 419254250691 76 419254250693 2 ...

  6. 利用CocoaPods管理本地工程和发布开源框架

    发布自己三方框架 发布云端库 1.创建spec pod spec create xxx 2.编辑spec s.name:名称,pod search 搜索的关键词,注意这里一定要和.podspec的名称 ...

  7. Data Structure Binary Tree: Connect nodes at same level using constant extra space

    http://www.geeksforgeeks.org/connect-nodes-at-same-level-with-o1-extra-space/ recursive: #include &l ...

  8. P3988 [SHOI2013]发牌

    题目 P3988 [SHOI2013]发牌 做法 我们切牌时的状态: 手玩几次后我们发现切\(K\)次牌就是求堆顶一下的\(K+1\)大值,套上主席树就好了 My complete code #inc ...

  9. python详细目录

    python第一篇 第二篇.初识列表字典元祖循环 第三篇.内置方法 第四篇.编码解码 列表.元祖 第五篇.数据类型 第六篇 函数 第七篇.函数二 第八篇.递归.装饰器 第九篇 正则表达式 第十篇.模块 ...

  10. 收缩VC数据库

    注意: 在收缩日志前必须截断事务日志. 一. SQL Server 2008 收缩日志 (1) 使用SQL管理器收缩日志 第一步执行如下命令 ALTER DATABASE dbname SET REC ...