每个箱子可有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 ;
}

最新文章

  1. Azkaban源码学习笔记
  2. 【转】linux内核中writesb(), writesw(), writesl() 宏函数
  3. [LeetCode] Decode Ways 解码方法
  4. python 3.5.2 install pillow
  5. 。net 文件依赖缓存
  6. 如何存session,取session
  7. JavaScript添加、查找、删除元素的一个实例
  8. [转]Raspberry Pi做成路由器
  9. Mac显示隐藏文件的终端命令
  10. An instance 0x172b8600 of class UITableView was deallocated while key value
  11. javascript 逻辑运算符
  12. Tableau学习笔记之五
  13. HDU 5821 Ball (贪心)
  14. Multi-Die系统介绍
  15. poj 3415 Common Substrings
  16. c#事件的应用
  17. [BZOJ]4200: [Noi2015]小园丁与老司机
  18. rman list 命令列举
  19. ios外派公司—提供ios程序员外派ios应用外包业务(北京动点 可签合同)
  20. 数据库入门理论知识介绍以及编译安装MySql

热门文章

  1. isinstance/issubclass/type的区别?
  2. 第一个Spring Boot程序启动报错了
  3. ubuntu service XXX start启动报start: Rejected send message, 1 matche
  4. deviceToken的获取(一)
  5. samsung n143 brightness on linux mint
  6. WPF之基础概念
  7. 【leetcode刷题笔记】Max Points on a Line
  8. 在Ubuntu上为Android系统的Application Frameworks层增加硬件访问服务【转】
  9. MHA高可用集群安装配置
  10. 红米note.线刷