您的位置:首页 > 其它

HDU 1069

2016-03-31 21:07 183 查看
// 题意 : 给出立方体长宽高 ,求摆放的最高高度,摆放在下面的立方体长宽大于上方的

#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 200;
int len[200];
struct node
{
int x,y,z;
void init(int xx,int yy, int zz)
{
x = xx; y = yy; z = zz;
}
};
node a[200];
bool cmp(node a,node b)
{
return (a.x*a.y < b.x*b.y);
}
int main()
{
int t=1,n,x,y,z;
while(scanf("%d",&n)!=EOF && n)
{
int cnt=0;
for(int i=0;i<n;i++)
{
scanf("%d%d%d",&x,&y,&z);
a[cnt++].init(x,y,z); a[cnt++].init(y,z,x);
a[cnt++].init(x,z,y); a[cnt++].init(y,x,z);
a[cnt++].init(z,x,y); a[cnt++].init(z,y,x);            //六种摆放的方式
}
sort(a,a+cnt,cmp); // 按底面积排序
int mx=0;
for(int i=0;i<cnt;i++ )  //LIS
{
len[i] = a[i].z;
for(int j=0;j<i;j++)
{
if(a[j].x < a[i].x && a[j].y < a[i].y)
{
len[i] = max(len[i], len[j] + a[i].z);
mx = max(mx, len[i]);
}

}
}
printf("Case %d: maximum height = %d\n",t++,mx);
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: