【HDU - 1069】 Monkey and Banana (基础dp)

Monkey and Banana

Write directly to the Chinese

Problem Statement

A group of researchers are designing an experiment to test the IQ of a monkey. They will hang a banana on the roof of the building, while some bricks to these monkeys. If the monkey is smart enough, it should be able to reasonably place some bricks to build a tower by, and climb to eat their favorite bananas.
 
Researchers there are n types of bricks, each brick has an infinite number of types. The i-th block of the block length and breadth respectively xi, yi, zi represented. Meanwhile, since the bricks are rotatable, each of the three sides of the block can be composed of six different length and breadth.
 
When in the construction of the tower, if and only if A brick length and width, respectively, are less than the length and width B brick, A brick bricks can be placed on top of B, because you must leave some space for the monkeys to step on .
 
Your task is to write a program that calculates the monkeys can pile up the bricks of their height.

Input

Input file contains several test cases.
The first line of each test case contains an integer n, representing the number of different types of bricks. n <= 30.
Next n lines, each line number 3, respectively represent the length and breadth of the bricks.
When n = 0 when the output without having any answers, the end of the test.

Output

For each test, the maximum output level. Format: Case of several sets of data: maximum height = maximum height

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

Sample Output 

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

Topic links:

https://vjudge.net/problem/HDU-1069

There are six ways a brick to be placed (1,2,3) (1,3,2) (2,1,3) (2,3,1) (3,1,2) (3,2,1 )

The above brick length (l), width (s) must be less than the following, respectively

dp [i] is the i-th time the bottom bricks are bricks that can reach the maximum height

AC Code

#include <bits/stdc++.h>
#define Mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x, y) memset(x, y, sizeof(x))
#define Maxn 1000
using namespace std;
struct node
{
    int l,s,h;//长 宽 高
    node(int l,int s,int h):l(l),s(s),h(h) {}
    bool operator<(const node &c)const//从小到大排序
    {
        if(l==c.l)
            return s<c.s;
        return l<c.l;
    }

};
vector<node> v;
int dp[Maxn];
int main()
{
    int n,k=0;
    while(cin>>n&&n!=0)
    {
        k++;
        v.clear();//清空,初始化
        MEM(dp,0);
        int cnt=0;
        int a,b,c;
        for(int= I 0 ; I <n-; I ++ ) 
        { 
            CIN >> A >> B >> C; // sequentially stored 
            v.push_back (Node (A, B, C)); 
            v.push_back (Node (A, C , B)); 
            v.push_back (Node (B, A, C)); 
            v.push_back (Node (B, C, A)); 
            v.push_back (Node (C, B, A)); 
            v.push_back (Node (C, A, B)); 
        } 
        Sort (v.begin (), v.end ()); // Sort 
        int ANS = 0 ;
         for ( int I = 0 ; I <v.size (); ++ I) // from the smallest piece of brick begin 
        { 
            DP [I]V = [I] .h; // start on this in a brick, DP [I] = V [I] .h 
            for ( int J = I- . 1 ; J> = 0 ; J,) // Start looking up smaller than its bricks 
            {
                 // j-th block brick length and width are smaller than the block i, j-th block and at the bottom of the brick height brick + i is greater than the height of the i-th order of bricks the height of the bottom, the update DP [I] 
                IF (V [J] .L <V [I] .L && V [J] .s <V [I] .s && DP [J] + V [I] .h> DP [ I]) 
                    DP [I] = DP [J] + V [I] .h; 
            } 
            IF (DP [I]> ANS) 
                ANS = DP [I]; 
        } 
        COUT << " Case " << K << ": maximum height = "<<ans<<endl;
    }
    return 0;
}

 

 

 

Guess you like

Origin www.cnblogs.com/sky-stars/p/12366945.html