HDU 1069 Monkey and Banana (struct sort, also belongs to simple DP)

Source: Internet
Author: User

Monkey and BananaTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others) Total Submission (s): 7770 Accepted Submission (s): 4003

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

Sourceuniversity of Ulm Local Contest 1996
Test instructions: Monkeys want to eat the fruit they want to eat, need to build a tower, the building tower, the height of the block above the length of the high, need to be larger than the following. is the structure sort. The code is as follows:
#include <stdio.h> #include <algorithm>using namespace std;struct block{int x, Y, Z;} A[222];int S[222];int CMP (block A,block b) {if (a.x==b.x) return A.y<b.y;elsereturn a.x<b.x;} int main () {int N;int c=1,m,i,j,x,y,z;while (~scanf ("%d", &n), n) {m=1;int maxi=0;for (i=0;i<n;i++)// All possibilities are filled into a array {scanf ("%d%d%d", &x,&y,&z); a[m].x=x,a[m].y=y,a[m].z=z;m++;a[m].x=x,a[m].y=z,a[m].z=y; M++;A[M].X=Y,A[M].Y=X,A[M].Z=Z;M++;A[M].X=Y,A[M].Y=Z,A[M].Z=X;M++;A[M].X=Z,A[M].Y=Y,A[M].Z=X;M++;A[M].X=Z,A[M] . y=x,a[m].z=y;m++;} m-=1;//because the last extra sort (a,a+m,cmp), for (i=1;i<=m;i++) s[i]=a[i].z;for (i=1;i<=m;i++) {for (j=1;j<=i;j++) {if (a[ J].X<A[I].X&&A[J].Y<A[I].Y&&S[I]<S[J]+A[I].Z)//need to be longer and wider than below, the higher the height of the better {s[i]=s[j]+a[i].z;if ( Maxi<s[i])//Find the highest height maxi=s[i];}} printf ("Case%d:maximum height =%d\n", C++,maxi);} return 0;}



Hdu 1069 Monkey and Banana (struct sort, also a simple DP)

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.