题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069
#include <stdio.h>
#include <string.h>
#define INF 9999999
int box[102][3],height[102];
int number;//砖块总数3*n+1
void oriente(int index,int a,int b,int c)
{//(a,b)是底面,c是高
box[index][0]=a;
box[index][1]=b;
box[index][2]=c;
}
int DP(int index)
{
int i,ret=0;
if(height[index]!=-1)
return height[index];
if(index>number)
return 0;
for(i=1;i<=number;++i)
{
if((box[index][0]>box[i][0]&&box[index][1]>box[i][1])
||(box[index][0]>box[i][1]&&box[index][1]>box[i][0]))
ret=DP(i)+box[i][2];
if(ret>height[index])
height[index]=ret;
}
return height[index];
}
int main()
{
int i,n,a,b,c,cases=1;
while(scanf("%d",&n)&&n)
{
box[0][0]=box[0][1]=box[0][2]=INF;//添加一地板
number=0;
for(i=0;i<n;++i)
{
scanf("%d %d %d",&a,&b,&c);
oriente(++number,a,b,c);
oriente(++number,b,c,a);
oriente(++number,c,a,b);
}
memset(height,-1,sizeof(height));
printf("Case %d: maximum height = %d\n",cases++,DP(0));
}
return 0;
}