HDOJ(1069)最长下降子序列
2024-08-27 12:12:18
每个箱子可有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 ;
}
最新文章
- Azkaban源码学习笔记
- 【转】linux内核中writesb(), writesw(), writesl() 宏函数
- [LeetCode] Decode Ways 解码方法
- python 3.5.2 install pillow
- 。net 文件依赖缓存
- 如何存session,取session
- JavaScript添加、查找、删除元素的一个实例
- [转]Raspberry Pi做成路由器
- Mac显示隐藏文件的终端命令
- An instance 0x172b8600 of class UITableView was deallocated while key value
- javascript 逻辑运算符
- Tableau学习笔记之五
- HDU 5821 Ball (贪心)
- Multi-Die系统介绍
- poj 3415 Common Substrings
- c#事件的应用
- [BZOJ]4200: [Noi2015]小园丁与老司机
- rman list 命令列举
- ios外派公司—提供ios程序员外派ios应用外包业务(北京动点 可签合同)
- 数据库入门理论知识介绍以及编译安装MySql
热门文章
- isinstance/issubclass/type的区别?
- 第一个Spring Boot程序启动报错了
- ubuntu service XXX start启动报start: Rejected send message, 1 matche
- deviceToken的获取(一)
- samsung n143 brightness on linux mint
- WPF之基础概念
- 【leetcode刷题笔记】Max Points on a Line
- 在Ubuntu上为Android系统的Application Frameworks层增加硬件访问服务【转】
- MHA高可用集群安装配置
- 红米note.线刷