hdu 1069

#include<iostream>
#include<algorithm>
using namespace std;

int n,i,j,ti;
int x,y,z,num;
struct Node{
    int x,y,z;       
};
Node nd[35*3];
int height[35*3];
//从小到大排序 
int cmp(Node a,Node b){
    return a.x>b.x;
}

int main(){
    while(cin>>n&&n){
        ti++;
        num=0;
        for(i=1;i<=n;i++){
            //对于x,y,z来说,将六种情况转化为三种情况,即按照从小到大的顺序
            //对x,y,z排序 ,排完序后,自身覆盖的情况只有一种
            //即y z作为底边覆盖x,y作为底边 
            cin>>x>>y>>z;
            int t;
            if(x>y)
               t=x,x=y,y=t;
            if(y>z)
               t=y,y=z,z=t;
            if(x>y)
               t=x,x=y,y=t;
            
            int tmp=num++;
            nd[tmp].x=x;
            nd[tmp].y=y;
            nd[tmp].z=z; 
                
            tmp=num++;
            nd[tmp].x=x;
            nd[tmp].y=z;
            nd[tmp].z=y;
            
            tmp=num++;
            nd[tmp].x=y;
            nd[tmp].y=z;
            nd[tmp].z=x;
        }
        sort(nd,nd+num,cmp);
        for(i=0;i<num;i++){
            height[i]=nd[i].z;
        }
        int tmp_max=-1,res=-1;
        for(i=0;i<num;i++){
            tmp_max=-1;
            for(j=0;j<i;j++){
                if(nd[i].x<nd[j].x&&nd[i].y<nd[j].y){
                    if(tmp_max<height[j])
                        tmp_max=height[j];
                }
            }
            if(tmp_max!=-1)
                height[i]=height[i]+tmp_max;
            if(res<height[i])
                res=height[i];                   
        }
        cout<<"Case "<<ti<<": "<<"maximum height = "<<res<<endl;
    }
    return 0;
}

你可能感兴趣的:(hdu 1069)