Hduoj1069 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): 2085 accepted submission (s): 1082

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 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 = 40 Case 2: maximum height = 21 case 3: maximum height = 28 case 4: maximum height = 342// 1069.cpp: defines the entry point of the console application. // # Include "stdafx. H "# include <map> # include <set> # include <list> # include <queue> # include <stack> # include <bitset> # include <vector> # include <string >#include <algorithm> # include <iostream> # include <cstdio> # include <cstring> # include <cmath> # include <cstdlib> # include <iomanip> using namespace std; # define max (x, y) (x)> (y )? (X) :( y) # define min (x, y) (x) <(y )? (X) :( y) const int maxint =-1u> 1; const double Pi = ACOs (-1.0); const int maxsize = 31*3; struct node {int A, B, C, H; // H is equivalent to opening another DP array // defining the sorting method, which is actually a descending order, you don't need to write a comparison function. You still think it is better to write a comparison function bool operator <(node Nb) const {if (! = Nb. a) return a> NB. A; If (B! = Nb. b) return B> NB. b; return C> NB. c;} // bool operator> (node Nb) const {return a> NB. A & B> NB. B ;}} node; int size [3]; // used for input. data can be pre-processed using arrays. Vector <node> block; // after reading the preceding data processing, it is simple. The simple dpvoid dp () {int I, j; int max = 0; for (I = 1; I <block. size (); ++ I) {for (j = 0; j <I; ++ J) {// dp soul: If (Block [J]> block [I] & // The area is strictly less than // block [I]. H = max {block [0... i-1]. h} + block [I]. c; // maximum height and front I-1 + I Height = block [I]. h <block [J]. H + block [I]. c) {block [I]. H = block [J]. H + block [I]. c ;}}// calculate the maximum value of all tower Heights if (max <block [I]. h) max = block [I]. h;} printf ("% d/N", max);} int main () {// freopen ("test.txt", "r", stdin); int I, n, cases; for (cases = 1; scanf ("% d", & N), N; ++ cases) {printf ("case % d: maximum height = ", cases); block. clear (); for (I = 0; I <n; ++ I) {scanf ("% d", & size [0], & siz E [1], & size [2]); // preprocessing means that there are only three cases for each cube. Otherwise, there are 6 types of sort (size, size + 3 ); // 1, 2, and 3 nodes. A = size [0]; node. B = size [1]; node. C = size [2]; node. H = node. c; block. push_back (node); node. A = size [1]; node. B = size [2]; node. C = size [0]; node. H = node. c; block. push_back (node); node. A = size [0]; node. B = size [2]; node. C = size [1]; node. H = node. c; block. push_back (node);} // sort it by DP ... Required sort (Block. Begin (), block. End (); DP ();} return 0 ;}

 

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.