Hdu 1069 Monkey and Banana --) dp

Source: Internet
Author: User

Hdu 1069 Monkey and Banana --) dp
Monkey and Banana: There are t groups of numbers, each group of three numbers, as a type of rectangular, length, width, height, because the height can be any of the three numbers, therefore, each three numbers can represent three different types of cubes.
Assume that there are infinite numbers of cubes. You can use the base block method (the top block must be strictly less than the bottom block ).
You can use dp to solve this question. First, we should put the case in front of the case, and sort the case from long to small. because there is a pair like (9, 1) (), and there is no guarantee that this sequence is as described in the meaning of the question, it is strictly monotonous and decreasing, so you cannot use greedy answers. recurrence: When two cubes numbered I and j are strictly monotonically decreasing, dp [I] = max (dp [j] + h, dp [I]).

Problem Description A group of researchers are designing an experiment to test the IQ of a monkey. they will hang 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 be able to reach the banana by placing one block on the top another to build a tower and climb up to get its favorite food.

The researchers have n types of blocks, and an unlimited supply of blocks of each type. each type-I block was a rectangular solid with linear dimensions (xi, yi, zi ). A block cocould be reoriented so that any two of its three dimensions determined the dimensions of the base and the other dimension was the height.

They want to make sure that the tallest tower possible by stacking blocks can reach the roof. the problem is that, in building a tower, one block cocould only be placed on top of another block as long as the two base dimensions of the upper block were both strictly smaller than the corresponding base dimensions of the lower block because there has to be some space for the monkey to step on. this meant, for example, that blocks oriented to have equal-sized bases couldn't be stacked.

Your job is to write a program that determines the height of the tallest tower the monkey can build with a given set of blocks.

Input The input file will contain in one or more test cases. The first line of each 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 are numbered sequentially starting from 1) and the height of the tallest possible tower in the format 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

Code:
#include
 
  #include
  
   #include
   
    #include#include
    
     #include
     
      #include
      
       using namespace std;#define maxf(a,b) a>b?a:bconst int inf=0x3f3f3f3f;struct node{ int l,w,h;} b[1000];bool cmp(node a, node b){ if(a.l==b.l) return a.w>b.w; return a.l>b.l;}int main(){ int t,fff=1; while(~scanf(%d,&t)&&t) { int j=0,a[4]; for(int i=0; i
       
        =0; i--) { for(int k=i+1; k
        
         b[k].l&&b[i].w>b[k].w) dp[i]=dp[i]>dp[k]+b[i].h?dp[i]:dp[k]+b[i].h; } max1=dp[i]>max1?dp[i]:max1; } printf(Case %d: maximum height = %d,fff++,max1); }}
        
       
      
     
    
   
  
 

 

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.