hdu1069 Monkey and Banana (rising longest sequence modification) (DP)

Monkey and Banana

Links: hdu1069

Problem Description

A group of researchers are designing a test lab monkey IQ. They would hang a banana on the roof, while the monkeys provide some building blocks. If the monkey is smart enough, then it should be able to reach the banana, put a building block on top of another building block, built a tower, then climb up to get its favorite food.
Researchers there are n blocks, the number of each building are unlimited. Each block is an i-type linear dimensions (xi, yi, zi) having a rectangular solid. An object may be re-oriented such that any two of its three dimensions may determine the dimensions of the base, the other dimension is the height.
They want to make sure that by stacking stones tallest tower to reach the roof. The problem is that, in the establishment of a column, a block can only be placed in another block as long as the two dimensions of the upper block substantially all strictly less than the lower dimension corresponding basic block, because there must be some space monkeys step. This means, for example, for a block having the same size of the base can not be stacked.
Your job is to write a program to determine the height of the tallest tower of monkeys can be given blocks built.

Entry

Input file will contain one or more test cases. The first line of each test case contains an integer n,
denotes the number of different blocks following the data set. maximum value of n is 30.
Each line contains the following n rows three integer value representing xi, yi and zi.
N 0 is the input (0) terminated.

Export

For each test case, in order to: print format "case case maximum height = height" line, which comprises using Example No. (sequentially numbered starting from 1) and maximum possible height of the tower.

Sample Input

1
10 20 30
2
6 8 10
5 5 5
7
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
5
31 41 59
26 53 58
97 93 23
84 62 64
33 83 27
0

Sample Output

Case 1: maximum height = 40
Case 2: maximum height = 21
Case 3: maximum height = 28
Case 4: maximum height = 342

analysis:

Similar requirements increase longest sequence
easiest increased demand longest sequence only determines the size of one dimension on the line.
But this question requires a long and wide are larger than the previous.
The solution is to give a one-dimensional ordering guarantees increments, then seek another dimension to rise longest sequence on the line.
Rise to the longest length of such sequences in ascending order, the required width.
But the adjacent rectangular length may be the same when it is judged not only to determine the width and the length should be judged together (to ensure strictly increasing)
(Also ask this question is the length of the longest sequence of height is not this just a little change to change on the line)

code:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
typedef long long ll;
const int inf=0x3f3f3f3f;
const int inn=0x80808080;
using namespace std;
const int maxm=1005;
struct Node{
    int a,b,c;
}a[maxm];
int d[maxm];//选到i时候的最大高度
int n;
int cnt;
int cas=1;
int cmp(Node a,Node b){
        return a.a<b.a;
}
int main(){
    while(cin>>n&&n){
        memset(d,0,sizeof d);
        cnt=0;
        for(int i=1;i<=n;i++){
            int aa,bb,cc;//长方体翻转之后有6种
            cin>>aa>>bb>>cc;
            a[++cnt].a=aa;//1
            a[cnt].b=bb;
            a[cnt].c=cc;
            a[++cnt].a=aa;//2
            a[cnt].b=cc;
            a[cnt].c=bb;
            a[++cnt].a=bb;//3
            a[cnt].b=aa;
            a[cnt].c=cc;
            a[++cnt].a=bb;//4
            a[cnt].b=cc;
            a[cnt].c=aa;
            a[++cnt].a=cc;//5
            a[cnt].b=bb;
            a[cnt].c=aa;
            a[++cnt].a=cc;//6
            a[cnt].b=aa;
            a[cnt].c=bb;
        }
        sort(a+1,a+cnt+1,cmp);
        int ans=0;
        for(int i=1;i<=cnt;i++){
            d[i]=a[i].c;
            for(int j=1;j<i;j++){
                if(a[j].a<a[i].a&&a[j].b<a[i].b){
                    d[i]=max(d[i],d[j]+a[i].c);
                }
            }
            ans=max(ans,d[i]);
        }
//        for(int i=1;i<=cnt;i++){//调试
//            cout<<a[i].a<<' '<<a[i].b<<' '<<d[i]<<endl;
//        }
        printf("Case %d: ",cas++);
        printf("maximum height = %d\n",ans);
    }
    return 0;
}


Guess you like

Origin blog.csdn.net/weixin_44178736/article/details/94621338