The Tower of BabylonTime
limit:3000MS
Memory Limit:0KB
64bit IO Format:%lld &%llu SubmitStatusPracticeUVA 437Appoint Description:System Crawler (2015-08-29)
Description
Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of this tale has been forgotten. So now, on line with the educational nature of this contest, we'll tell you the whole story:
The Babylonians had n types of blocks, and an unlimited supply of blocks of each type. Each type-I block is a rectangular solid with linear dimensions. A Block could is reoriented so it three dimensions determined the dimensions of the base and the other Di Mension was the height. They wanted to construct the tallest tower possible by stacking blocks. The problem was, building a tower, one block could is placed on top of another block as long as the Dimensions of the upper block were both strictly smaller than the corresponding base dimensions of the lower block. This is meant, for example, which blocks oriented to has equal-sized bases couldn ' t be stacked.
Your job is to write a program this determines the height of the tallest tower the Babylonians can build with a given set of blocks.
Input and Output
The input file is contain one or more test cases. The first line of all test case contains a integer n, representing the number of different blocks in the follow ing data set. The maximum value for n is 30. Each of the next n lines contains three integers representing the values, and.
Input is terminated by a value of zero (0) for N.
For each test case, print one line containing the case number (they is numbered sequentially starting from 1) and the HEI Ght of the tallest possible tower in the format "case case: maximum height =height"
Sample Input
110 20 3026 8 105 5 571 1 12 2 23 3 34 4 45 5 56 6 67 7 7531 41 5926 53 5897 93 2384 62 6433 83 270
Sample Output
Case 1:maximum height = 40Case 2:maximum height = 21Case 3:maximum height = 28Case 4:maximum height = 342
1#include <stdio.h>2#include <string.h>3#include <algorithm>4 using namespacestd;5 6 structNode7 {8 intl;9 intR;Ten inth; One ints; A }; - -Node a[ -]; the - BOOLCMP (Node p,node q) - { - returnp.s<Q.s; + } - + intMain () A { at intN,n; - inti,j,k=1; - intdp[ -]; - while(SCANF ("%d", &n)!=eof && n!=0) - { -n=0; inMemset (DP,0,sizeof(DP)); - for(i=1; i<=n;i++) to { + intx, y, z -scanf" %d%d%d",&x,&y,&z); then++; *A[n].l=max (x, y), a[n].r=min (x, y), a[n].h=z,a[n].s=x*y; $n++;Panax NotoginsengA[n].l=max (X,z), A[n].r=min (x,z), a[n].h=y,a[n].s=x*Z; -n++; theA[n].l=max (Z,y), A[n].r=min (z,y), a[n].h=x,a[n].s=z*y; + } A theSort (A +1, a+n+1, CMP); +dp[n]=a[n].h; - intans=Dp[n]; $ for(i=n-1; i>=1; i--) $ { - intmax=0; - for(j=i+1; j<=n;j++) the { - if(A[I].L<A[J].L && A[I].R<A[J].R && dp[j]>max)Wuyimax=Dp[j]; the } -dp[i]=max+a[i].h; Wu if(dp[i]>ans) -ans=Dp[i]; About } $ -printf"Case %d:maximum height =%d\n", k++, ans); - } - return 0; A}View Code
UVA 4,379 the Tower of Babylon