POJ 2241 the Tower of Babylon

Source: Internet
Author: User

The Tower of Babylontime limit:1000msmemory limit:65536kbthis problem'll be judged onPKU. Original id:2241
64-bit integer IO format: %lld Java class name: Main 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 (xi, Yi, zi). 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.InputThe input would contain one or more test cases. The first line of all test case contains an integer n,
Representing the number of different blocks in the following data set. The maximum value for n is 30.
Each of the next n lines contains three integers representing the values XI, Yi and Zi.
Input is terminated by a value of zero (0) for N.OutputFor 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
SourceULM Local 1996 Problem Solving: Dynamic programming, much like Lis
1#include <bits/stdc++.h>2 using namespacestd;3 Const intMAXN =10010;4 structcube{5     intx, y, z6Cube (intA =0,intb =0,intc =0){7x =A;8y =b;9z =C;Ten     } One     BOOL operator< (ConstCube &t)Const{ A         returnX*y > t.x*T.y; -     } - }CUBE[MAXN]; the intDP[MAXN]; - intMain () { -     intN,tot,x,y,z,kase =1; -      while(SCANF ("%d",&N), N) { +          for(inti = tot =0; I < n; ++i) { -scanf"%d%d%d",&x,&y,&z); +cube[tot++] =Cube (x, y, z); Acube[tot++] =Cube (y,z,x); atcube[tot++] =Cube (x,z,y); -         } -Memset (DP,0,sizeofDP); -Sort (cube,cube+tot); -         intMaxHeight =0; -          for(inti =0; i < tot; ++i) { inDp[i] =cube[i].z; -              for(intj = I1; J >=0; --j) { to                 if(cube[j].x > cube[i].x && cube[j].y >cube[i].y) +Dp[i] = max (Dp[i],dp[j] +cube[i].z); -                 if(Cube[j].y > cube[i].x && cube[j].x >cube[i].y) theDp[i] = max (Dp[i],dp[j] +cube[i].z); *             } $MaxHeight =Max (maxheight,dp[i]);Panax Notoginseng         } -printf"Case %d:maximum height =%d\n", kase++, maxheight); the     } +     return 0; A}
View Code

POJ 2241 the Tower of Babylon

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.