Algorithm title: UVA 437 The Tower of Babylon (DP + dag longest sequence)

Source: Internet
Author: User
The Tower of Babylon

Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of this tale have been forgotten. So now, in line with the educational of the contest, we'll tell you the whole story:

The Babylonians had n types of blocks, and a unlimited supply of blocks of each type. Each type-i blocks is a rectangular solid with linear dimensions . A Block could is reoriented so, any two of 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. The problem was then, in building a tower, one blocks could only is placed on top of another block as long as the two base Dimensions of the upper block were both strictly smaller than the corresponding base dimensions to the lower block. This is meant, for example, which blocks oriented to have equal-sized the bases ' t be couldn.

Your job is to write a program that determines the height of the tallest tower the Babylonians can builds with a given set of blocks.

Input and Output

The input file would contain one or more test cases. The ' a ' of each 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 .

The Input is terminated by a value of zero (0) for N.

For each test case, print one line containing the case number (they are numbered sequentially starting from 1) and the HEI Ght of the tallest possible tower in the format case : Maximum height = height

Sample Input

1
2
6 8 ten 5
5 5 7 1
1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 + 6 7
  5 to the
0 in which he was a

Sample Output

Case 1:maximum height = case
2:maximum height = case
3:maximum height = case
4:maximum height = 342

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.