hdu 1069

就是枚举每种情况,然后因为不可能有相等的情况出现,所以最多是每种情况都出现一次,也就是n*6然后

dp[i][j] = dp[i][k] + h[k] ( x[k] > x[j] && y[k] > y[j] )

就是每次找比自己块小的之中最高的然后更新状态

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#define MAX 187

using namespace std;

int n;

struct Node
{
    int x ,y , z;
    Node ( int a , int b , int c )
        : x ( a ) , y ( b ) , z ( c ){}
};

int dp[MAX][MAX];

bool judge (  const Node& a ,const Node& b )
{
    if ( a.x >= b.x ) return false;
    if ( a.y >= b.y ) return false;
    if ( a.x*a.y >= b.x*b.y ) return false;
    return true;
}

int main ( )
{
    int x,y,z;
    int c = 1;
    while ( ~scanf ( "%d" , &n ) , n )
    {
        vector<Node> v;
        for ( int i = 1 ; i <= n ; i++ )
        {
            scanf ( "%d%d%d" , &x , &y , &z );
            v.push_back ( Node ( x , y , z ) );
            v.push_back ( Node ( y , x , z ) );
            v.push_back ( Node ( x , z , y ) );
            v.push_back ( Node ( z , x , y ) );
            v.push_back ( Node ( y , z , x ) );
            v.push_back ( Node ( z , y , x ) );
        }
        n = n*6;
        int ans = 0;
        int len = v.size();
        memset ( dp , 0 , sizeof ( dp ) );
        for ( int i = 0 ; i < n ; i ++ )
            dp[0][i] = v[i].z;
        for ( int i = 1 ; i <= n ; i++ )
            for ( int j = 0 ; j < len ; j++ )
                for ( int k = 0 ; k < len ; k++ )
                {
                    if ( k == j ) continue;
                    if ( !judge ( v[j] , v[k] ) ) continue;
                    dp[i][j] = max ( dp[i-1][k] + v[j].z , dp[i][j] );   
                    ans = max ( dp[i][j] , ans ); 
                }
        printf ( "Case %d: maximum height = " , c++ );
        printf ( "%d\n" , ans );
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值