zju1093

来源:互联网 发布:php cms使用 编辑:程序博客网 时间:2024/06/07 10:44

#include<iostream>

using namespace std;

#define max_n 30

 

typedef struct node{

       int a,b;

       int h;

}node;

 

node boxes[3*max_n+10];

int n;

 

int cmp(const void *a,const void *b)

{

       node * temp1=(node *)a;

       node * temp2=(node *)b;

       if(temp1->a != temp2->a)

       {

              return (temp1->a - temp2->a);

       }

       else

       {

              return (temp1->b - temp2->b);

       }

}

 

inline int max(int a,int b)

{ if(a>=b) return a; else return b;}

 

 

 

 

void make()

{

       int b[3*max_n+10];

       int i;

       int j;

 

       b[0]=boxes[0].h;

       for( i=1;i<3*n;i++)

       {

              b[i]=boxes[i].h;

              for( j=0;j<i;j++)

              {

                     if(boxes[i].a > boxes[j].a  &&  boxes[i].b > boxes[j].b)

                            b[i]=max(b[i],b[j]+boxes[i].h);

              }

       }

       int max_h=0;

       for(i=0;i<3*n;i++)

              max_h=max(max_h,b[i]);

       cout<<max_h<<endl;

}

 

int main()

{

       int i;

       cin>>n;

       int a,b,h;

       int test=1;

       while(n)

       {

              for(i=0;i<3*n;i+=3)

              {

                     cin>>a>>b>>h;

                     boxes[i].a=a;    boxes[i].b=b;    boxes[i].h=h;

                     boxes[i+1].a=h;  boxes[i+1].b=a;  boxes[i+1].h=b;

                     boxes[i+2].a=b;  boxes[i+2].b=h;  boxes[i+2].h=a;

              }

              for(i=0;i<3*n;i++)

              {

                     int temp;

                     if(boxes[i].a>boxes[i].b)

                     {

                            temp=boxes[i].a;   boxes[i].a=boxes[i].b;   boxes[i].b=temp;

                     }

              }

              qsort(boxes,3*n,sizeof(boxes[0]),cmp);

              cout<<"Case "<<test++<<": maximum height = ";

              make();

              cin>>n;

       }

       return 0;

}

 

 

 

 

 

 
原创粉丝点击