急求杭电1069的代码?该如何解决

急求杭电1069的代码???
Monkey and Banana
Problem Description
A group of researchers are designing an experiment to test the IQ of a monkey. They will hang a banana at the roof of a building, and at the mean time, provide the monkey with some blocks. If the monkey is clever enough, it shall be able to reach the banana by placing one block on the top another to build a tower and climb up to get its favorite food.
The researchers have n types of blocks, and an unlimited supply of blocks of each type. Each type-i block was a rectangular solid with linear dimensions (xi, yi, zi). A block could be reoriented so that any two of its three dimensions determined the dimensions of the base and the other dimension was the height. 
They want to make sure that the tallest tower possible by stacking blocks can reach the roof. The problem is that, in building a tower, one block could only be placed on top of another block as long as the two base dimensions of the upper block were both strictly smaller than the corresponding base dimensions of the lower block because there has to be some space for the monkey to step on. This meant, for example, that blocks oriented to have equal-sized bases couldn't be stacked. 
Your job is to write a program that determines the height of the tallest tower the monkey can build with a given set of blocks.
 
Input
The input file will contain one or more test cases. The first line of each test case contains an integer n,
representing the number of different blocks in the following data set. The maximum value for n is 30.
Each of the next n lines contains three integers representing the values xi, yi and zi.
Input is terminated by a value of zero (0) for n.
 
Output
For each test case, print one line containing the case number (they are numbered sequentially starting from 1) and the height of the tallest possible tower in the format "Case case: maximum height = height".
 
Sample Input
1
10 20 30
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

中文:
问题描述:
一群研究人员正设计一个研究猴子IQ的实验。他们悬挂一只香蕉在楼房的屋顶,同时提供猴子一些石头。如果这些猴子是足够聪明的,它将要得到自己最爱的食物通过把石头塔成塔来完成。
研究人员有n种不同的石头,每一种石头都无限制的提供。第i种石头是一个矩形和长度为(Xi,Yi,Zi)。三个长度中的任意两个决定一个基底,另一个就是高度。
他们想要确定能够到达屋顶最高的塔的高度。问题是,在建塔的过程中,要注意随着塔高度的上升,上面一块石头基底尺寸要比下面那块的尺寸严格小,因为要留点空间给猴子站脚,也就是说上下两块石头的基底大小不能相同。
你的任务是写一个程序来确定塔的最高的高度。

输入描述:
输入包括多组测试数据,每组测试的第一行包含一个整数n代表n种不同的石头,n最大可达到30。下面的n行,每行包含3个整数Xi,Yi,Zi,当输入为0时,文件结束。

输出描述:
对于每组测试数据,输出塔的最高高度,格式为Case case(the case number): maximum height = height

输入样例:
1
10 20 30
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

输出样例:
Case 1: maximum height = 40
Case 2: maximum height = 21
Case 3: maximum height = 28
Case 4: maximum height = 342
帮帮忙 谢谢了!!!

------解决方案--------------------
题目:给出一些长方体,然后让你把他堆成塔,要求下面的塔的要比上面的塔大(长和宽),而且每一种长方体的数量都是无限的。因为每一个长方体都有x,y,z,所以对应的可以用的长方体应该有三个,就是这个长方体的x,y,z分别做为高。这样,每一个输入的长方体就得处理成三个,然后按他们的上面积进行排序,dp就可以做出来了 具体看代码就知道了
C/C++ code
#include <stdio.h>
#include <stdlib.h>
struct cube
{
int s;
int l;
int w;
int h;
int sum;
}a[100];
int cmp(const void *a,const void *b)
{
return *(int *)b-*(int *)a;
}
bool isSuit(cube i,cube j)
{
    return i.l<j.l&&i.w<j.w || i.w<j.l&&i.l<j.w;
}
int main ()
{
int n,i,j,top,c=0;
while (scanf("%d",&n)!=EOF)
{
   c++;
   if (n==0) return 0;
   for (i=0;i<n*3;i++)
   {
    scanf("%d %d %d",&a[i].l,&a[i].w,&a[i].h);
    a[i].s=a[i].l*a[i].w;i++;
    a[i].l=a[i-1].h;a[i].w=a[i-1].w;a[i].h=a[i-1].l;
    a[i].s=a[i].l*a[i].w;i++;
    a[i].l=a[i-2].l;a[i].w=a[i-2].h;a[i].h=a[i-2].w;
    a[i].s=a[i].l*a[i].w;
   }
   qsort(a,3*n,sizeof(a[0]),cmp);
   a[0].sum=a[0].h;
   for(i=1;i<3*n;i++)
   {
    top=0;
    for (j=0;j<i;j++)
    {
     if(a[j].sum>top&&isSuit(a[i],a[j]))
       top=a[j].sum;
    }
    a[i].sum=a[i].h+top;
   }
   top=0;
   for (i=0;i<3*n;i++)
    if (top<a[i].sum) top=a[i].sum;
   printf ("Case %d: maximum height = %d\n",c,top);
}
return 0;
}