• UVA 437 十九 The Tower of Babylon


    The Tower of Babylon
    Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu
    Appoint description: 

    Description

    Download as PDF
     

    Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of this tale have been forgotten. So now, in line with the educational nature of this contest, we will tell you the whole story:

    The babylonians had n types of blocks, and an unlimited supply of blocks of each type. Each type-i block was a rectangular solid with linear dimensions tex2html_wrap_inline32 . A block could be reoriented so that any two of its three dimensions determined the dimensions of the base and the other dimension was the height. They wanted to construct the tallest tower possible by stacking blocks. The problem was that, in building a tower, one block could only be placed on top of another block as long as the two base dimensions of the upper block were both strictly smaller than the corresponding base dimensions of the lower block. This meant, for example, that blocks oriented to have equal-sized bases couldn't be stacked.

    Your job is to write a program that determines the height of the tallest tower the babylonians can build with a given set of blocks.

    Input and Output

    The input file will contain one or more test cases. The first line of each 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 tex2html_wrap_inline40 , tex2html_wrap_inline42 and tex2html_wrap_inline44 .

    Input is terminated by a value of zero (0) for n.

    For each test case, print one line containing the case number (they are numbered sequentially starting from 1) and the height of the tallest possible tower in the format "Casecase: maximum height =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
    0

    Sample Output

    Case 1: maximum height = 40
    Case 2: maximum height = 21
    Case 3: maximum height = 28
    Case 4: maximum height = 342
     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <algorithm>
     4 using namespace std;
     5 
     6 struct Node 
     7 {
     8     int l;
     9     int r;
    10     int h;
    11     int s;
    12 };
    13 
    14 Node a[100];
    15 
    16 bool cmp(Node p,Node q)
    17 {
    18     return p.s<q.s;
    19 }
    20 
    21 int main()
    22 {
    23     int N,n;
    24     int i,j,k=1;
    25     int dp[100];
    26     while(scanf("%d",&N)!=EOF && N!=0)
    27     {
    28         n=0;
    29         memset(dp,0,sizeof(dp));
    30         for(i=1;i<=N;i++)
    31         {
    32             int x,y,z;
    33             scanf("%d %d %d",&x,&y,&z);
    34             n++;
    35             a[n].l=max(x,y),a[n].r=min(x,y),a[n].h=z,a[n].s=x*y;
    36             n++;
    37             a[n].l=max(x,z),a[n].r=min(x,z),a[n].h=y,a[n].s=x*z;
    38             n++;
    39             a[n].l=max(z,y),a[n].r=min(z,y),a[n].h=x,a[n].s=z*y;
    40         }
    41 
    42         sort(a+1,a+n+1,cmp);
    43         dp[n]=a[n].h;
    44         int ans=dp[n];
    45         for(i=n-1;i>=1;i--)
    46         {
    47             int max=0;
    48             for(j=i+1;j<=n;j++)
    49             {
    50                 if(a[i].l<a[j].l && a[i].r<a[j].r && dp[j]>max)
    51                     max=dp[j];
    52             }
    53             dp[i]=max+a[i].h;
    54             if(dp[i]>ans)
    55                 ans=dp[i];
    56         }
    57 
    58         printf("Case %d: maximum height = %d
    ",k++,ans);
    59     }
    60     return 0;
    61 }
    View Code
  • 相关阅读:
    Problem F
    Problem L
    Problem L
    Problem B
    Problem B
    读书笔记-Java设计模式
    读书笔记-内存初始化和清理
    读书笔记- 一切都是对象
    Android多点触控技术实战,自由地对图片进行缩放和移动
    Native开发与JNI机制详解
  • 原文地址:https://www.cnblogs.com/cyd308/p/4771618.html
Copyright © 2020-2023  润新知