HDU 1069 Monkey and Banana (LIS longest ascending sub-sequence), hdulis

Source: Internet
Author: User

HDU 1069 Monkey and Banana (LIS longest ascending sub-sequence), hdulis
B-LISTime Limit:1000 MSMemory Limit:32768KB64bit IO Format:% I64d & % I64u

Description

A group of researchers are designing an experiment to test the IQ of monkeys. They will mount bananas on the roof of the building and provide some bricks to the 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 bananas. Researchers have n types of bricks, each of which has an infinite number. The length, width, and height of block I are represented by xi, yi, and zi respectively. At the same time, because bricks can be rotated, three sides of each brick can form six different types of length, width, and height. When building A tower, when and only when the length and width of brick A are smaller than the length and width of brick B, brick A can be placed on the top of brick B, because there must be some space for monkeys to step on. Your task is to compile a program to calculate the height of the bricks that the monkeys can heap up.

Input

The input file contains multiple groups of test data. The first line of each test case contains an integer n, representing the number of bricks of different types. N <= 30. Next n rows, each line contains three numbers, indicating the length, width, and height of the bricks. When n = 0, no answers are output. The test is over.

Output

The maximum output height for each group of test data. Format: Case group of 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
31 41 59
26 53 58
97 93 23
84 62 64
33 83 27
0

Sample Output

Case 1: maximum height = 40 Case 2: maximum height = 21
Case 3: maximum height = 28
Case 4: maximum height = 342

Suppose that the given cubes are stacked together, and their length, width, and height can be exchanged freely. The condition of the superposition is that the length and width of the cube above are longer than the length of the cube below.

And width and short; find the highest height of the top layer of the long side. (3, 2, 1) can be placed into (3, 2, 1) (3, 1, 2), (2, 1, 3 ). what can I see in the previous sentence ?? If not, continue reading.

Thought: in fact, it is to find the longest monotonic decreasing sequence. When the length and width decrease, the maximum height obtained by the maximum energy is obtained.

 

# Include <iostream> # include <algorithm> # include <cstdio> using namespace std; struct node {int l, w, h;} a [111]; int dp [111]; int cmp (node a, node B) {if (. l> B. l) return 1; if (. l = B. l &. w> B. w) return 1; else return 0;} int main () {int B [3], t, n, k, sum, f = 1; while (cin> t & t) {k = 0; for (int I = 0; I <t; I ++) {cin> B [0]> B [1]> B [2]; sort (B, B + 3 );
// Remember, this question can be thought like this. The length must be greater than the width, otherwise it will not be long, so you only need to find the three cases with the height a [k]. l = B [2]; a [k]. w = B [1]; a [k]. h = B [0]; // the smallest height of each cube k ++; a [k]. l = B [2]; a [k]. w = B [0]; a [k]. h = B [1]; // high k ++ OF THE SECOND height of each cuboid; a [k]. l = B [1]; a [k]. w = B [0]; a [k]. h = B [2]; // The highest k ++ of each cube;} sort (a, a + k, cmp); for (int I = 0; I <k; I ++) dp [I] = a [I]. h; for (int I = K-2; I> = 0; I --) // next layer for (int j = I + 1; j <k; j ++) // The previous layer {if (a [I]. l> a [j]. l & a [I]. w> a [j]. w) // if (dp [I] <dp [j] + a [I]. h) // if a larger height is found, update dp [I] = dp [j] + a [I]. h;} sum = dp [0]; for (int I = 0; I <k; I ++) if (sum <dp [I]) sum = dp [I]; printf ("Case % d: maximum height = % d \ n", f ++, sum);} return 0 ;}

Related Article

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.