#include<stdio.h>//如何转换为dp..思维开发.ps:每一个dp题目都有他独特的魅力.
#include<stdlib.h>//如何变成的最长递增子序列:首先.每个长方体可以无限用.决定了一个长方体可以
#include<math.h>//变形为6个长方体.(当然,没必要去考虑边想同的.减少不了什么复杂度和空间.
#include<iostream>//然后,网上说的都是去比较x,y||S(面积),仔细的分析了一下.觉得没必要
#include<vector>//排序的目的只是为了达到使得后面的不可能有机会出现在前面的上面.
#include<string.h>//即,只要有一个x or y比前面的大就可以了...为什么要这样呢.?
using namespace std;//就要说到这里的状态了..状态是dp的基本.没有考虑状态和状态转移永远无法入门dp.
//这里的状态即是,对于当前的i去遍历之前的所有木头.如果.能够满足题目的条件,那么木头i就可以出现在
//该木头的下面.即dp[i] = dp[j]+test[i].z,遍历过程中找到一个最大的dp[i];
//即是第i个木头能够形成的最优解.因为i后面的木头永远不可能出现在i的上方.所有这样遍历出来的结果
//一定是最优解.
const int inf = 0x3f3f3f;
struct Test
{
int x,y,z;
Test(int x , int y ,int z):x(x),y(y),z(z){};
Test(){};
};
int mutiply(Test m[] , int p , int r)
{
int i = p -1 , j = r + 1;
int a = m[p].x;
while(1)
{
i++;
while(m[i].x < a)i++;
j--;
while(m[j].x > a)j--;
if(i < j)
{
Test ex = m[j];
m[j] = m[i];
m[i] = ex;
}
else return j;
}
}
void quicsort(Test m[] , int p ,int r)
{
if(p < r)
{
int q = mutiply(m,p,r);
quicsort(m,p,q);
quicsort(m,q+1,r);
}
}
int dp[2000];
Test test[2000];
int main()
{
int n,x,y,z,maxx,tt = 0;
while(scanf("%d",&n) && n != 0)
{
tt++;
int t = 1;
for(int i = 1 ; i <= n ; i++)
{
scanf("%d%d%d",&x,&y,&z);
{
test[t].x = x;test[t].y = y;test[t++].z = z;
test[t].x = y;test[t].y = z;test[t++].z = x;
test[t].x = z;test[t].y = x;test[t++].z = y;
test[t].x = x;test[t].y = z;test[t++].z = y;
test[t].x = y;test[t].y = x;test[t++].z = z;
test[t].x = z;test[t].y = y;test[t++].z = x;
}
}
quicsort(test,1,6*n);
// for(int i = 1 ; i <= 6 * n ; i++)
// {
// printf("i == %d %d %d %d\n",i,test[i].x,test[i].y,test[i].z);
// }
int maxx = -inf;
for(int i = 1 ; i <= n*6 ; i++)
{
dp[i] = test[i].z;
for(int j = 1 ; j < i ; j++)
{
if(test[i].x > test[j].x && test[i].y > test[j].y && dp[i] < dp[j] + test[i].z)
{
dp[i] = dp[j] + test[i].z;
}
}
if(dp[i] > maxx)maxx = dp[i];
}
// for(int i = 1 ; i <= 6 * n ; i++)
// printf("dp[%d] == %d\n",i,dp[i]);
printf("Case %d: maximum height = %d\n",tt,maxx);
}
}
#include<stdlib.h>//如何变成的最长递增子序列:首先.每个长方体可以无限用.决定了一个长方体可以
#include<math.h>//变形为6个长方体.(当然,没必要去考虑边想同的.减少不了什么复杂度和空间.
#include<iostream>//然后,网上说的都是去比较x,y||S(面积),仔细的分析了一下.觉得没必要
#include<vector>//排序的目的只是为了达到使得后面的不可能有机会出现在前面的上面.
#include<string.h>//即,只要有一个x or y比前面的大就可以了...为什么要这样呢.?
using namespace std;//就要说到这里的状态了..状态是dp的基本.没有考虑状态和状态转移永远无法入门dp.
//这里的状态即是,对于当前的i去遍历之前的所有木头.如果.能够满足题目的条件,那么木头i就可以出现在
//该木头的下面.即dp[i] = dp[j]+test[i].z,遍历过程中找到一个最大的dp[i];
//即是第i个木头能够形成的最优解.因为i后面的木头永远不可能出现在i的上方.所有这样遍历出来的结果
//一定是最优解.
const int inf = 0x3f3f3f;
struct Test
{
int x,y,z;
Test(int x , int y ,int z):x(x),y(y),z(z){};
Test(){};
};
int mutiply(Test m[] , int p , int r)
{
int i = p -1 , j = r + 1;
int a = m[p].x;
while(1)
{
i++;
while(m[i].x < a)i++;
j--;
while(m[j].x > a)j--;
if(i < j)
{
Test ex = m[j];
m[j] = m[i];
m[i] = ex;
}
else return j;
}
}
void quicsort(Test m[] , int p ,int r)
{
if(p < r)
{
int q = mutiply(m,p,r);
quicsort(m,p,q);
quicsort(m,q+1,r);
}
}
int dp[2000];
Test test[2000];
int main()
{
int n,x,y,z,maxx,tt = 0;
while(scanf("%d",&n) && n != 0)
{
tt++;
int t = 1;
for(int i = 1 ; i <= n ; i++)
{
scanf("%d%d%d",&x,&y,&z);
{
test[t].x = x;test[t].y = y;test[t++].z = z;
test[t].x = y;test[t].y = z;test[t++].z = x;
test[t].x = z;test[t].y = x;test[t++].z = y;
test[t].x = x;test[t].y = z;test[t++].z = y;
test[t].x = y;test[t].y = x;test[t++].z = z;
test[t].x = z;test[t].y = y;test[t++].z = x;
}
}
quicsort(test,1,6*n);
// for(int i = 1 ; i <= 6 * n ; i++)
// {
// printf("i == %d %d %d %d\n",i,test[i].x,test[i].y,test[i].z);
// }
int maxx = -inf;
for(int i = 1 ; i <= n*6 ; i++)
{
dp[i] = test[i].z;
for(int j = 1 ; j < i ; j++)
{
if(test[i].x > test[j].x && test[i].y > test[j].y && dp[i] < dp[j] + test[i].z)
{
dp[i] = dp[j] + test[i].z;
}
}
if(dp[i] > maxx)maxx = dp[i];
}
// for(int i = 1 ; i <= 6 * n ; i++)
// printf("dp[%d] == %d\n",i,dp[i]);
printf("Case %d: maximum height = %d\n",tt,maxx);
}
}