HDUOJ1069 Monkey and Banana

來源:互聯網
上載者:User

 

Monkey and Banana

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2085    Accepted Submission(s): 1082

Problem DescriptionA 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 could 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 could 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.

 

 

InputThe input file will contain 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. 

 

OutputFor 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 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// 1069.cpp : 定義控制台應用程式的進入點。//#include "stdafx.h"#include <map>#include <set>#include <list>#include <queue>#include <stack>#include <bitset>#include <vector>#include <string>#include <algorithm>#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <iomanip>using namespace std;#define max(x,y) ((x)>(y)?(x):(y))#define min(x,y) ((x)<(y)?(x):(y))const int MAXINT = -1u>>1;const double pi = acos(-1.0);const int MaxSize=31*3 ;struct Node{    int a, b, c, h ;//h相當於另外開一個dp的數組//定義排序方式,其實是從大到小的排序,就不用寫比較函數了,還是覺得寫比較函數比較好    bool operator < ( Node nb )const{        if( a != nb.a )            return a > nb.a ;        if( b != nb.b )            return b > nb.b ;        return c > nb.c ;    }//在DP比較的時候有用到    bool operator > ( Node nb )const{        return a>nb.a && b>nb.b ;    }} node ;int size[3] ;//輸入的時候用的,用數組可以將資料進行預先處理vector<Node> block ;//看完前面的資料處理到這裡就簡單了,簡單的DPvoid dp(){    int i, j ;int Max=0 ;    for( i=1; i<block.size(); ++i ){        for( j=0; j<i; ++j ){//DP的靈魂求            if( block[j]>block[i] && //面積嚴格小於//block[i].h = max{block[0...i-1].h} + block[i].c;//前i-1的最大高度和 + i的高度 = 以i為頂的塔的最大高度block[i].h<block[j].h+block[i].c ){                block[i].h = block[j].h+block[i].c ;}        }//求所有塔高的最大值if( Max < block[i].h )Max = block[i].h ;    }        printf("%d/n", Max ) ;}int main(){    //freopen("test.txt", "r", stdin ) ;     int i, n, cases ;    for( cases=1; scanf("%d",&n), n; ++cases ){        printf("Case %d: maximum height = ", cases ) ;        block.clear() ;        for( i=0; i<n; ++i ){            scanf("%d %d %d", &size[0], &size[1], &size[2] ) ;//預先處理這樣每個立方體就只有3種情況了,不然的話是6種            sort( size, size+3 ) ;//1、2、3            node.a = size[0] ; node.b = size[1] ;            node.c = size[2] ;            node.h = node.c ;            block.push_back( node ) ;            node.a = size[1] ;            node.b = size[2] ;            node.c = size[0] ;            node.h = node.c ;            block.push_back( node) ;            node.a = size[0] ;            node.b = size[2] ;            node.c = size[1] ;            node.h = node.c ;            block.push_back( node ) ;        }//將其排序後DP,至於為什麼要排序。。。題目要求的        sort( block.begin(), block.end() ) ;                dp() ;    }    return 0 ;}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.