/*
跟矩阵嵌套一样
*/
#include<stdio.h>
#include<stdlib.h>
int num=0;
struct node
{
int x,y,z;
}blocks[200];
int high[200];
int cmp(const void *a,const void *b)
{
struct node *c=(struct node *)a,*d=(struct node *)b;
if(c->x!=d->x)
return c->x-d->x;
else return c->y-d->y;
}
int he(int j,int i)
{
if(blocks[i].x>blocks[j].x&&blocks[i].y>blocks[j].y)
return 1;
if(blocks[i].x>blocks[j].y&&blocks[i].y>blocks[j].x)
return 1;
return 0;
}
void dp(int n)
{
int i,j;
high[0]=blocks[0].z;
for(i=1;i<n;i++)
{
int max=0;
for(j=0;j<i;j++)
{
if(he(j,i)&&high[j]>max)
max=high[j];
}
high[i]=max+blocks[i].z;
}
int max=high[0];
for(i=1;i<n;i++)
if(high[i]>max)
max=high[i];
high[0]=max;
}
int main()
{
int n,i,xx,yy,zz,j;
while(scanf("%d",&n),n)
{
j=0;
num++;
for(i=0;i<n;i++)
{
scanf("%d%d%d",&xx,&yy,&zz);
blocks[j].x=xx;
blocks[j].y=yy;
blocks[j++].z=zz;
blocks[j].x=xx;
blocks[j].y=zz;
blocks[j++].z=yy;
blocks[j].x=yy;
blocks[j].y=xx;
blocks[j++].z=zz;
blocks[j].x=yy;
blocks[j].y=zz;
blocks[j++].z=xx;
blocks[j].x=zz;
blocks[j].y=xx;
blocks[j++].z=yy;
blocks[j].x=zz;
blocks[j].y=yy;
blocks[j++].z=xx;
}
qsort(blocks,n*6,sizeof(blocks[0]),cmp);
dp(6*n);
printf("Case %d: maximum height = %d\n",num,high[0]);//忘了输出格式,刚开始只输出一个数
}
return 0;
}
hdu 1069 Monkey and Banana--最长递增子序列
最新推荐文章于 2022-02-25 19:38:17 发布