HDU 1069 Monkey and Banana (max monotonically descending sequence ah dp)

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1069


Problem Descriptiona Group of researchers is designing a 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.

Inputthe input file would 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.

Outputfor each test case, print one line containing the case number (they is numbered sequentially starting from 1) and T He height of the tallest possible tower in the format "case 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 = 40Case 2:maximum height = 21Case 3:maximum height = 28Case 4:maximum height = 342

Sourceuniversity of Ulm Local Contest 1996

Test instructions

The given box (not limited to) superimposed together, the condition is that the upper box is longer and wider than the box below the length of


And the width of the box can be superimposed on the highest height. (3,2,1) can be placed (3,1,2), (2,1,3), etc.).

PS: Each block has a maximum of 3 different bottom and height, we can think of each block as three different building blocks, so the N speciestypes of bricks are converted into3*N adifferent bricks, on this3*Nthe length of a building block is sorted from large to small;Then find a descending subsequence that makes the height and maximum of the sub-sequences.
The code is as follows:

#include <cstdio> #include <cstring> #include <algorithm> #include <iostream>using namespace    std;struct node{int L, W, H;} A[1047];bool CMP (Node A, Node B) {if (a.l = = B.L) {return a.w > B.W; } return A.L > B.L;}    int MAX (int a, int b) {if (a > B) return A; return b;}    int Dp[1047];//dp[i]: maximum height with block i blocks int main () {int n;    int cas = 0;        while (scanf ("%d", &n) && N) {//int L, W, H;        int tt[3];        int k = 0;            for (int i = 0; i < n; i++) {scanf ("%d%d%d", &tt[0],&tt[1],&tt[2]);            Sort (tt,tt+3);            A[K].L = tt[0];            A[K].W = tt[1];            A[k].h = tt[2];            k++;            A[K].L = tt[1];            A[K].W = tt[2];            A[k].h = tt[0];            k++;            A[K].L = tt[0];            A[K].W = tt[2];            A[k].h = tt[1];        k++;        } sort (a,a+k,cmp);        int maxx = 0; for (int i = 0; I < K;            i++) {Dp[i] = a[i].h;                for (int j = i-1; J >= 0; j--) {if (a[j].l>a[i].l && A[J].W&GT;A[I].W)                {Dp[i] = MAX (Dp[i], dp[j]+a[i].h);            }} if (Dp[i] > Maxx) {maxx = Dp[i];    }} printf ("Case%d:maximum height =%d\n", ++cas,maxx); } return 0;}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 1069 Monkey and Banana (max monotonically descending sequence ah dp)

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.