ZOJ 1093 Monkey and Banana

Source: Internet
Author: User

ZOJ 1093 Monkey and Banana

 

Question: Give You n bricks of different specifications. Tell you the length, width, and height of the bricks. There are no number of bricks of each type, and there are bricks of different sizes (strictly less than, not equal) you can stack on long and wide bricks and ask how high you can stack.

Train of Thought: Tell you that a type of Brick actually gives you three types of bricks, because the bricks can be flipped, And the length, width, and height can be changed;

Take the length as the first variable and the width as the second variable, and sort the values from large to small. In this way, the Top n blocks can only be selected from the first n-1 blocks, select the maximum value, and accumulate the height.

The Code is as follows:

 

#include 
 
  #include 
  
   #include 
   
    #include const int N = 35;using namespace std;int n;int dp[3*N];struct node{int x, y, z;bool operator< (const node &rhs) const{if(x != rhs.x) return x > rhs.x;return y > rhs.y;}}block[3*N];int main(){int cnt = 1;    while(~scanf(%d, &n))    {    int a, b, c;    if(n == 0) break;        for(int i = 0, x, y, z; i < 3 * n; i ++)        {        scanf(%d%d%d, &x, &y, &z);        a = max(max(x, y), z);        c = min(min(x, y), z);        b = (x + y + z) - (a + c);        block[i].x = a, block[i].y = b, block[i].z = c;        block[++i].x = a, block[i].y = c, block[i].z = b;        block[++i].x = b, block[i].y = c, block[i].z = a;        }        sort(block, block + 3 * n);        int maxn;        for(int i = 0; i < 3*n; i++)        {        maxn = 0;        for(int j = 0; j < i; j++)        {        if(block[j].x > block[i].x && block[j].y > block[i].y &&  block[j].z > maxn)        {        maxn = block[j].z;        }        }        block[i].z += maxn;        }        maxn = 0;        for(int i = 0; i < 3*n; i++)        {        if(maxn < block[i].z)        {        maxn = block[i].z;        }        }        printf(Case %d: maximum height = %d, cnt, maxn);        cnt ++;    }    return 0;}
   
  
 
 

Related Article

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.