Description
Input
Output
Sample Input
2
6 8 10
5 5 5
7
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
5
31 41 59
26 53 58
97 93 23
84 62 64
33 83 27
0
Sample Output
Case 1: maximum height = 40
Case 2: maximum height = 21
Case 3: maximum height = 28
Case 4: maximum height = 342
#include<cstdio>
#include<algorithm>
using namespace std;
struct brick
{
int a,b,c;
bool operator<(const brick &x)const
{
return a<x.a||a==x.a&&b<x.b;
}
};
brick x[130];
long long dp[130];
int main()
{
int n,a[3],k=1;
while(scanf("%d",&n)&&n)
{
int f=0;
for(int i=0; i<n; i++)
{
scanf("%d%d%d",&a[0],&a[1],&a[2]);
sort(a,a+3);
x[f].a=a[0];
x[f].b=a[1];
x[f].c=a[2];
f++;
x[f].a=a[0];
x[f].b=a[2];
x[f].c=a[1];
f++;
x[f].a=a[1];
x[f].b=a[0];
x[f].c=a[2];
f++;
x[f].a=a[1];
x[f].b=a[2];
x[f].c=a[0];
f++;
}
sort(x,x+f);
for(int i=0; i<f; i++)
dp[i]=x[i].c;
long long ans=0;
for(int i=0; i<f; i++)
{
int maxn=0;
for(int j=i-1; j>=0; j--)
if(x[i].a>x[j].a&&x[i].b>x[j].b)
{
if(maxn<dp[j])
{
maxn=dp[j];
}
}
dp[i]+=maxn;
ans=max(ans,dp[i]);
}
printf("Case %d: maximum height = %I64d\n",k++,ans);
}
return 0;
}