DP [HDU 1069] Monkey and banana

Source: Internet
Author: User
Monkey and banana

Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 7854 accepted submission (s): 4051


Problem descriptiona group of researchers are designing an experiment to test the IQ of a monkey. they will hang a banana at the roof of a building, and at the mean time, provide the monkey with some blocks. if the monkey is clever enough, it shall be able to reach the banana by placing one block on the top another to build a tower and climb up to get its favorite food.

The researchers have n types of blocks, and an unlimited supply of blocks of each type. each type-I block was a rectangular solid with linear dimensions (XI, Yi, zi ). A block cocould be reoriented so that any two of its three dimensions determined the dimensions of the Base and the other dimension was the height.

They want to make sure that the tallest tower possible by stacking blocks can reach the roof. the problem is that, in building a tower, one block cocould only be 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 of the Lower Block because there has to be some space for the monkey to step on. this meant, for example, that blocks oriented to have equal-sized bases couldn't be stacked.

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

 

Inputthe input file will contain in one or more test cases. The first line of each 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 are numbered sequentially starting from 1) and the height of the tallest possible tower in the format "case: maximum height = height ".

 

Sample input110 20 3026 8 105 5 57 1 1 12 2 23 3 34 4 45 5 56 6 67 7 7531 41 5926 5897 93 2384 62 6433 270

 

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

 

Sourceuniversity of Ulm Local contest 1996

 

Lis variants, code above, =
# Include <iostream> # include <cstdio> # include <algorithm> using namespace STD; # define max (a, B) (a)> (B )? (A) :( B) # define n 100100 struct rect {int x, y, z; bool operator <(const rect & T) const {If (X! = T. x) return x <t. x; return Y <t. Y ;}} s [N]; int main () {int DP [N]; // DP [I] indicates the maximum height of int n ending with the cube I, i, j, M, icase = 0; while (scanf ("% d", & M), m) {n = 0; memset (DP, 0, sizeof (DP); While (M --) {int x, y, z; scanf ("% d", & X, & Y, & Z ); s [++ N]. X = x; s [N]. y = y; s [N]. z = z; If (s [N]. x <s [N]. y) Swap (s [N]. x, s [N]. y); s [++ N]. X = x; s [N]. y = z; s [N]. z = y; If (s [N]. x <s [N]. y) Swap (s [N]. x, s [N]. y); s [++ N]. X = z; s [N]. y = y; s [N]. z = x; If (s [N]. x <s [N]. y) Swap (s [N]. x, s [N]. y);} Sort (S + 1, S + n + 1); for (I = 1; I <= N; I ++) {DP [I] = s [I]. z; For (j = 1; j <I; j ++) {If (s [I]. x> S [J]. X & S [I]. y> S [J]. y) DP [I] = max (DP [I], DP [J] + s [I]. z) ;}} int ans =-1; for (I = 1; I <= N; I ++) {ans = max (ANS, DP [I]);} printf ("case % d: maximum height = % d \ n", ++ icase, ANS);} return 0 ;}

 

 

DP [HDU 1069] Monkey and banana

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.