C-monkey and Banana

Source: Internet
Author: User

C-monkey and BananaTime limit:1000MS Memory Limit:32768KB 64bit IO Format:%i64d &%i64 U SubmitStatus

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 Master prepares me DP The second way. DP comparison Slag, a start to read the title, see there are n kinds of items, each unlimited, added some restrictions, feeling a bit like a complete backpack. But that would have been completely awry. Although each kind of stone has infinite, but because of the condition limit ... Each type of stone cannot take more than one .... Positive solutions should be sorted first and then one of the longest descending sub-sequences note that each stone has 6 different methods (some say three kinds ...). Do not understand) when reading in the process can be. See someone by area sort also can ac, feel wrong, each edge of limit, by area sort is obviously relaxed condition ... Is it because of data water?
#include <iostream>#include<algorithm>#include<cstring>#include<cstdio>#include<cmath>using namespacestd; intn,k,a,b,c,tmp; Const intn=1e4+5; intDp[n]; Long Longans;structq{intx, Y, Z;} Q[n];BOOLCMP (Q a,q b) {if(a.x>b.x)return true; if(A.X==B.X&AMP;&AMP;A.Y&GT;B.Y)return true; return false;}intMain () {intcas=0;  while(SCANF ("%d", &n)!=eof&&N) {CAs++; Memset (DP,0,sizeof(DP)); K=1; Ans= -1;  for(inti =1; I <= N; i++) {scanf ("%d%d%d",&a,&b,&c); q[k].x= A;Q[K].Y = b;q[k].z=c;k++; q[k].x= A;Q[K].Y = c;q[k].z=b;k++; q[k].x= B;Q[K].Y = a;q[k].z=c;k++; q[k].x= B;Q[K].Y = c;q[k].z=a;k++; q[k].x= C;Q[K].Y = a;q[k].z=b;k++; q[k].x= C;Q[K].Y = b;q[k].z=a;k++; } k--; Sort (q+1, q+k+1, CMP); dp[1]=q[1].z;  for(inti =2; I <= K; i++) {tmp=0;  for(intj =1; J <= I-1; J + + )                if(q[j].x>q[i].x&&q[j].y>q[i].y&&dp[j]>tmp) {tmp=Dp[j]; } Dp[i]=tmp+q[i].z; }         for(inti =1; I <= K; i++)            if(dp[i]>ans) ans=Dp[i]; printf ("Case %d:maximum height =%i64d\n", Cas,ans); }    return 0;}

C-monkey and Banana

Related Article

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.