zoukankan      html  css  js  c++  java
  • UVA 437 The Tower of Babylon

    dp

     1 #include <iostream>
     2 #include <cstring>
     3 #include <cstdio>
     4 #include <algorithm>
     5 using namespace std;
     6 
     7 struct node {
     8     int x,y,h;
     9     void init (int nx,int ny,int nh){
    10         x=nx;y=ny;h=nh;
    11     }
    12 }d[100];
    13 
    14 int dp[100];
    15 int g[100][100];
    16 
    17 bool cmp (node x,node y){
    18     if (x.x<y.x)
    19         return true ;
    20     else if (x.x==y.x){
    21         if (x.y<y.y)
    22             return true ;
    23         else if (x.y==y.y){
    24             if (x.h<y.h)
    25                 return true ;
    26         }
    27     }
    28     return false ;
    29 }
    30 
    31 int main (){
    32     int n;
    33     int kase=0;
    34     while (cin>>n&&n){
    35         for (int i=0;i<n;i++){
    36             int x[5];
    37             cin>>x[0]>>x[1]>>x[2];
    38             sort (x,x+3);
    39             d[i*3].init (x[0],x[1],x[2]);
    40             d[i*3+1].init (x[0],x[2],x[1]);
    41             d[i*3+2].init (x[1],x[2],x[0]);
    42         }
    43         n*=3;
    44         sort (d,d+n,cmp);
    45         memset (g,0,sizeof g);
    46         for (int i=0;i<n;i++){
    47             for (int j=0;j<n;j++){
    48                 if (d[i].x<d[j].x&&d[i].y<d[j].y)
    49                     g[j][i]=1;
    50             }
    51                 dp[i]=d[i].h;//cout<<dp[i]<<endl;
    52         }
    53         for (int i=0;i<n;i++){
    54             for (int j=0;j<n;j++){
    55                 if (g[i][j])
    56                     dp[i]=max (dp[i],dp[j]+d[i].h);//cout<<i<<j<<" "<<dp[i]<<endl;
    57             }
    58         }
    59         int ans=0;
    60         for (int i=0;i<n;i++)
    61             ans=max (ans,dp[i]);
    62         cout<<"Case "<<++kase<<": maximum height = "<<ans<<endl;
    63     }
    64     return 0;
    65 }
  • 相关阅读:
    The nineteenth day
    The eighteen day
    弱读下
    弱读上
    失爆 爆破音
    连读
    The seventeenth day
    The sixteenth day
    React 官方脚手架 create-react-app快速生成新项目
    pc端引入微信公众号文章
  • 原文地址:https://www.cnblogs.com/gfc-g/p/3877645.html
Copyright © 2011-2022 走看看