5thweek.problem_b (Zoj 1093) LIS

Source: Internet
Author: User

Description

A group of researchers are designing an experiment to test the IQ of monkeys. They will hang bananas on the roof of the building, while providing some bricks to these monkeys. If the monkey is smart enough, it should be able to build a tower by reasonably placing some bricks and climb up to eat their favorite banana. The researchers have n types of bricks, each of which has an infinite number of bricks. The length and width height of block I bricks are indicated by Xi,yi,zi. At the same time, because the bricks can be rotated, the 3 sides of each brick can make up 6 different lengths of height and width. When building towers, a bricks can be placed above the B bricks only if the length and width of a bricks are smaller than the length and width of the B bricks respectively, because there must be room for the monkeys to step on. Your task is to write a program that calculates the height of the bricks that the monkeys can pile up.

Input

The input file contains multiple sets of test data. The first line of each test case contains an integer n, representing the number of different kinds of bricks. N<=30. Next n rows, 3 numbers per line, respectively, representing the length and width of the bricks. When n=At 0, the test ends without having to output any answers.

Output

For each set of test data, the output is the maximum height. Format: CaseGroup data: Maximum height = Maximum height

Sample Input

110 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  , 59 , 58  23 , 64  27  0 

Sample Output

Case 1:maximum height = 40Case 2:maximum height = 21Case 3:maximum height = 4:maximum height = 342 Topic Analysis: 1. Define a structure that stores the length and width of a brick, and the length and width of a brick, each of which can be rotated, so that the six states of the brick can be stored directly into the structure array.    Init (A,B,C); Init (a,c,b; init (B,A,C); Init ( b,c,a); init (c,a,b); init (c,b,a) ; 2. The array of this body chart is then sorted by: length, width, height from small to large. 3. State Transitions Code and brief analysis:
1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5 using namespacestd;6 structcuboid7 {8     intl,w,h;9}cu[ the];Ten intdp[ the]; One  A intK; - voidInitintXintYintz) - { theCu[k].l=x; Cu[k].w=y; Cu[k].h=z; k++; - } - BOOLcmpConstCuboid &a,ConstCuboid &b) - { +     if(a.l==B.L) -     { +         if(a.w==B.W) A             returna.h<b.h; at         //Else -         returna.w<B.W; -     } -     //Else -     returna.l<B.L; - } in  - intMain () to { +   intn,i,j,a,b,c,maxn,t=1; -    while(Cin>>n &&N) the   { *k=0, maxn=0; $      for(i=0; i<n;i++)Panax Notoginseng     { -scanf"%d%d%d",&a,&b,&c); the init (a,b,c); + init (a,c,b); A init (b,a,c); the init (b,c,a); + init (c,a,b); - init (c,b,a); $     } $Sort (cu,cu+k,cmp); -    //For (i=0;i<k;i++) -      //cout<<cu[i].l<< "" <<cu[i].w<< "" <<cu[i].h<<endl; the  -      for(i=0; i<k;i++)Wuyi     { thedp[i]=cu[i].h; -     } Wu      for(i=1; i<k;i++) -     { About          for(j=0; j<i;j++)//J<i and J=0 start, j must not be equal to I $        { -         if(CU[I].L&GT;CU[J].L && CU[I].W&GT;CU[J].W && dp[j]+cu[i].h>Dp[i]) -             { -dp[i]=dp[j]+cu[i].h; A                if(maxn<Dp[i]) +maxn=Dp[i]; the             } -        } $     } theprintf"Case %d:maximum height =%d\n", t++, MAXN); the   } the  the   return 0; -}

5thweek.problem_b (Zoj 1093) LIS

Related Keywords:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.