hdu 1069

来源:互联网 发布:围棋定式软件 编辑:程序博客网 时间:2024/06/05 01:06

就是枚举每种情况,然后因为不可能有相等的情况出现,所以最多是每种情况都出现一次,也就是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 187using 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 );    }}


0 0
原创粉丝点击