HDU 1069 DP Longest increment subsequence

Source: Internet
Author: User

B-monkey and BananaTime limit:1000MS Memory Limit:32768KB 64bit IO Format:%i64d &%i6 4u Submit Status Practice HDU 1069Appoint Description:

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

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 each lattice can form 6 State, up to 180 states,,,,,, and X, y as the judging condition, accumulate Z-value
#include <stdio.h>#include<string.h>#include<iostream>#include<algorithm>using namespacestd;structnode{intx, Y, Z;} que[ $];intdp[ $];inttot;voidAddedge (intXintYintz) {que[tot].x=x; Que[tot].y=y; Que[tot++].z=Z; que[tot].x=x; Que[tot].y=Z; Que[tot++].z=y; que[tot].x=y; Que[tot].y=x; Que[tot++].z=Z; que[tot].x=y; Que[tot].y=Z; Que[tot++].z=x; que[tot].x=Z; Que[tot].y=x; Que[tot++].z=y; que[tot].x=Z; Que[tot].y=y; Que[tot++].z=x;}BOOLcmpstructNode T1,structnode T2) {     if(t1.x!=t2.x)returnT1.x>t2.x; Else if(t1.x==t2.x&&t1.y!=t2.y)returnT1.y>t2.y; Else         returnT1.z>t2.z;}intMain () {intN; intcas=1;  while(SCANF ("%d", &n)! =EOF) {       if(!N) Break; Memset (DP,0,sizeof(DP)); Tot=1; intx, Y, Z  for(intI=0; i<n;i++) {scanf ("%d%d%d",&x,&y,&z);       Addedge (x, y, z); } sort (que+1, que+tot+1, CMP); dp[1]=que[1].z;  for(intI=2; i<tot;i++) {Dp[i]=que[i].z;  for(intj=i-1; j>=1; j--){              if(que[i].x<que[j].x&&que[i].y<que[j].y&&dp[i]<dp[j]+que[i].z) Dp[i]=dp[j]+que[i].z; }       }       intans=-1;  for(intI=1; i<tot;i++) ans=Max (ans,dp[i]); printf ("Case %d:maximum height =%d\n", cas++, ans); }   return 0;}

HDU 1069 DP Longest increment subsequence

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.