思路
一种砖块可以旋转成不同的六种,将这六种都加入到队列中,然后就变成了最长上升子序列。
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=31*6;
struct Node {
int x,y,z;
} a[N];
bool cmp(Node a,Node b)
{
if(a.x!=b.x) return a.x<b.x;
else return a.y<b.y;
}
int f[N];
int n,cnt,t;
int main()
{
while(cin>>n,n)
{
cnt=0;
memset(f,0,sizeof f);
for(int i=0;i<n;i++)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
a[cnt++]={x,y,z};
a[cnt++]={x,z,y};
a[cnt++]={y,x,z};
a[cnt++]={y,z,x};
a[cnt++]={z,x,y};
a[cnt++]={z,y,x};
}
sort(a,a+cnt,cmp);
int ans=0;
for(int i=0;i<cnt;i++)
{
f[i]=a[i].z;
for(int j=0;j<i;j++)
{
if(a[i].x>a[j].x&&a[i].y>a[j].y)
{
f[i]=max(f[i],f[j]+a[i].z);
}
}
}
for(int i=0;i<cnt;i++) ans=max(ans,f[i]);
printf("Case %d: maximum height = %d\n",++t,ans);
}
return 0;
}