acm-Classic DP Monkey and banana--hdu1069

Source: Internet
Author: User

*************************************** Reprint Please specify the Source:Http://blog.csdn.net/lttree***************************************Monkey and BananaTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 6984 Accepted Submission (s): 3582

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

Source

Field=problem&key=university%20of%20ulm%20local%20contest%201996&source=1&searchmode=source "style= "Color:rgb (26,92,200); Text-decoration:none ">university of Ulm Local Contest 1996 topic:

pid=1069 ">http://acm.hdu.edu.cn/showproblem.php?

pid=1069

A classic DP topic, similar to finding the longest increment subsequence.

Test Instructions: a bunch of scientists studied the ape's IQ and gave him M-box. Each of N.

Then, hang a banana on the roof and let the gorilla reach the banana by stacking the box.
now give you M kind of cuboid, calculate, maximum can heap how high. the length of the box above is required to be greater than (note is not greater than or equal to) the length of the box below. The width of the box above is wider than the box below.


Problem Solving: a cuboid. can have 6 different pendulum methods. as there are up to 30 types of box in the data. Which means that the largest array can be opened to 30*6=180 fully capable
then use Dp[i] to save, to the first block I, the highest can be tired high. of course. Box first to the length of the order, the same length is small on the width.
(⊙v⊙) well. ok~

/********************************************************************************** Author:Tree                       **from:http://blog.csdn.net/lttree * * Title:monkey and Banana **source:hdu 1069 * * HINT:DP ******************************************************************************** **/#include <iostream> #include <algorithm>using namespace std;struct cuboid{int l,w,h;}    Cd[181];int dp[181];//Sort Compare function bool cmp (Cuboid cod1,cuboid cod2) {if (COD1.L==COD2.L) return cod1.w<cod1.w; return COD1.L&LT;COD2.L;}    int main () {int i,j,n,len,t_num=1;    int z1,z2,z3;        while (Cin>>n && N) {len=0;            Each set of numbers can be transformed into 6 cuboid for (i=0;i<n;++i) {cin>>z1>>z2>>z3;            cd[len].l=z1,cd[len].w=z2,cd[len++].h=z3;            CD[LEN].L=Z1,CD[LEN].W=Z3,CD[LEN++].H=Z2;      cd[len].l=z2,cd[len].w=z1,cd[len++].h=z3;      CD[LEN].L=Z2,CD[LEN].W=Z3,CD[LEN++].H=Z1;            CD[LEN].L=Z3,CD[LEN].W=Z1,CD[LEN++].H=Z2;        CD[LEN].L=Z3,CD[LEN].W=Z2,CD[LEN++].H=Z1;        } sort (cd,cd+len,cmp);                Dp[0]=cd[0].h;        Build the DP array int max_h;            for (i=1;i<len;++i) {max_h=0;                    for (J=0;J&LT;I;++J) {if (cd[j].l<cd[i].l && CD[J].W&LT;CD[I].W)            max_h=max_h>dp[j]?max_h:dp[j];        } Dp[i]=cd[i].h+max_h;        }//Search again for the maximum value of all DP max_h=0;        for (I=0;i<len;++i) if (Max_h<dp[i]) max_h=dp[i];    Output cout<< "case" <<t_num++<< ": Maximum height =" <<max_h<<endl; } return 0;}


acm-Classic DP Monkey and banana--hdu1069

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.