Monkey and Banana
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)Total Submission (s): 7823 Accepted Submission (s): 4033
Problem Description
A group of researchers is designing an experiment to test the IQ of a monkey. They 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 being able to reach the banana by placing one block on the top another to build a to Wer and climb up to get their favorite food.
The researchers has 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 want to make sure, the tallest tower possible by stacking blocks can reach the roof. The problem is that, in building a tower, one block could only being placed on top of the another block as long as the the and the both base D Imensions of the upper block were both strictly smaller than the corresponding base dimensions of the lower block because There have to is some space for the monkey to step on. 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 monkey can build with a given set of BL Ocks.
Input
The input file is 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.
Output
For 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
1
10 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
The main topic: there are bananas on the roof, and the monkeys have n blocks of x*y*z bricks with a long width and height. Monkeys want to
Base a brick tower to eat bananas. Base tower when the upper brick must be strict than the bottom of the brick small (top brick
Long < bottom brick length && top brick width < bottom brick width). Bricks have countless blocks and ask how high the highest can be.
Idea: Although there are countless blocks of bricks. However, the size of the X-wide Y-scale brick can only be used one piece.
As the upper and lower bricks
Both length and width are unequal. But a brick has a good variety of methods. Here is the first X, Y. Z increments the sort. Built
A method for the storage and placement of a structural body.
Let X be wide, y is long, Z is high as a pendulum, and X is wide. Z is
Long, Y is high as a pendulum, Y is wide. Z is long, X is high for the third pendulum.
Why not place the long-wide swap position as a pendulum?
In fact, this is not necessary.
Plus it's right. It's not wrong to add or not.
Because the height of the upper and lower brick is strictly unequal.
If you let X be long. Y is wide and z is high.
If x, Y, Z are not the same length. According to the above three kinds of pendulum method.
The bottom of the brick for the width of y, the length of z, the height of the bricks of X.
On the top of the brick for the width of x. A brick with a length of y and a height of Z.
There is also a piece of brick that cannot be placed.
plus Y is wide. x is long. Z is high after the brick. cannot be placed.
Similarly, the other two kinds of placement methods are not established.
After all the bricks are placed, the floor area (length * width) of the bricks is arranged in ascending order.
This is followed by the largest and the longest increment subsequence.
#include <stdio.h> #include <string.h> #include <algorithm>using namespace std;struct block{int x; int y; int z; int area;} Block[330];int Dp[330];int CMP (block A,block b) {return A.area < B.area;} int main () {int n,a[3],kase = 1; while (~SCANF ("%d", &n) && N) {int num = 0; Memset (Dp,0,sizeof (DP)); memset (block,0,sizeof (Block)); for (int i = 0; i < N; i++) {scanf ("%d%d%d", &a[0],&a[1],&a[2]); Sort (a,a+3); block[num].x = A[0],block[num].y = A[1],block[num].z = A[2],block[num].area = block[num].x*block[num].y,num++; block[num].x = A[1],block[num].y = A[2],block[num].z = A[0],block[num].area = block[num].x*block[num].y,num++; block[num].x = A[0],block[num].y = A[2],block[num].z = A[1],block[num].area = block[num].x*block[num].y,num++; } sort (block,block+num,cmp); int Max = 0; for (int i = 0; i < num; i++) {Dp[i] = block[i].z; for (int j = 0; J < i; J + +) {if (block[j].x < block[i].x && Block[j].y < Block[i ].Y) Dp[i] = max (DP[I],DP[J]+BLOCK[I].Z); } max = max (Dp[i],max); } printf ("Case%d:maximum height =%d\n", Kase++,max); } return 0;}
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
Hdu1069_monkey and Banana "LCS"