HDU 1069 Monkey and Banana (DP)

Source: Internet
Author: User

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


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
recommendjgshining | We have carefully selected several similar problems for you:1176 1058 1159 1024 1257

Separates each box into 6, which, after sorting, resembles the maximum ascending subsequence.

#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <string > #include <algorithm> #include <cstdlib> #include <set> #include <queue> #include <stack > #include <vector> #include <map> #define N 100#define Mod 10000007#define Lson l,mid,idx<<1#define  Rson mid+1,r,idx<<1|1#define LC idx<<1#define RC Idx<<1|1const Double EPS = 1e-11;const double PI = ACOs ( -1.0); const double E = 2.718281828;typedef long long ll;const int INF = 1000010;using namespace Std;int n,len;struct E    dge {int c,k,h;} e[n*3];int dp[n*3];bool cmp (Edge E1,edge E2) {if (e1.c==e2.c) return e1.k<e2.k; return e1.c<e2.c;}    void Add_edge (int x,int y,int z) {e[len].c=x;    E[len].k=y;    E[len].h=z; len++;} BOOL OK (int I,int j) {return (e[i].c>e[j].c&& (E[I].K&GT;E[J].K));}    int main () {int ca=1;        while (cin>>n&&n) {len=0;        int x, y, Z; for (int i=0; i<n;i++) {scanf ("%d%d%d", &x,&y,&z);            Add_edge (x, y, z);            Add_edge (X,z,y);            Add_edge (Y,Z,X);            Add_edge (Y,X,Z);            Add_edge (Z,x,y);        Add_edge (Z,Y,X);        } sort (e,e+len,cmp);        int ans=-10100100;            for (int i=0; i<len; i++) {dp[i]=e[i].h;                for (int j=0; j<=i; J + +) if (OK (i,j)) {Dp[i]=max (dp[i],dp[j]+e[i].h);        } ans=max (Ans,dp[i]);    } printf ("Case%d:maximum height =%d\n", Ca++,ans); } return 0;}


HDU 1069 Monkey and Banana (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.