zoukankan      html  css  js  c++  java
  • HDOJ 1069 Monkey and Banana

    1:每一组X,Y,Z对应3个立方体
    2:按面积从小到大DP

    Monkey and Banana

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 5356    Accepted Submission(s): 2744


    Problem Description
    A group of researchers are designing an experiment to test the IQ of a monkey. They will hang 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 be able to reach the banana by placing one block on the top another to build a tower and climb up to get its favorite food.

    The researchers have n types of blocks, and an unlimited supply of blocks of each type. Each type-i block was a rectangular solid with linear dimensions (xi, yi, zi). 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 want to make sure that the tallest tower possible by stacking blocks can reach the roof. The problem is 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 because there has to be some space for the monkey to step on. 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 monkey can build with a given set of blocks.
     
    Input
    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 xi, yi and zi.
    Input is terminated by a value of zero (0) for n.
     
    Output
    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 "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
     
    Source
     
    Recommend
    JGShining
     
     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstring>
     4 
     5 using namespace std;
     6 
     7 struct cube
     8 {
     9     int l,w,h;
    10     int sum;
    11 }cc[111];
    12 
    13 bool ifso(cube a,cube b)
    14 {
    15     return (a.l<b.l&&a.w<b.w)||(a.w<b.l&&a.l<b.w);
    16 }
    17 
    18 bool cmp(cube a,cube b)
    19 {
    20     return a.l*a.w>b.l*b.w;
    21 }
    22 
    23 int main()
    24 {
    25     int n;
    26     int cnt=1;
    27     while(cin>>n&&n)
    28     {
    29         memset(cc,0,sizeof(cc));
    30         for(int i=0;i<3*n;i++)
    31         {
    32             int L,W,H;
    33             cin>>L>>W>>H;
    34             cc[i].l=L;cc[i].w=W;cc[i].h=H;cc[i].sum=0;i++;
    35             cc[i].l=W;cc[i].w=H;cc[i].h=L;cc[i].sum=0;i++;
    36             cc[i].l=H;cc[i].w=L;cc[i].h=W;cc[i].sum=0;
    37         }
    38 
    39         sort(cc,cc+3*n,cmp);
    40 
    41         for(int i=0;i<3*n;i++)
    42         {
    43             int temx=0;
    44             for(int j=0;j<i;j++)
    45             {
    46                 if(cc[j].sum>temx&&ifso(cc[i],cc[j]))
    47                     temx=cc[j].sum;
    48             }
    49             cc[i].sum=temx+cc[i].h;
    50         }
    51 
    52         int ans=-1;
    53         for(int i=0;i<3*n;i++)
    54         {
    55             ans=max(ans,cc[i].sum);
    56         }
    57 
    58         cout<<"Case "<<cnt++<<": maximum height = "<<ans<<endl;
    59     }
    60 
    61     return 0;
    62 }
  • 相关阅读:
    0918作业-----所有数值未做合法性检测
    尝试安装和配置JDK,并给出安装、配置JDK的步骤
    java为什么可以跨平台执行
    字符集
    java 入门及简介
    时间轴特效
    javascript简介
    javascript while循环
    Javascript for循环
    函数豹子问题
  • 原文地址:https://www.cnblogs.com/CKboss/p/3097742.html
Copyright © 2011-2022 走看看