UVa 11218 KTV

UVa 11218 KTV
采用很暴力的办法即可。
以下是我的代码:
#include < algorithm >
#include
< cstdio >
using   namespace  std;
const   int  kMaxn( 87 );

struct  Type
{
    
int  a_,b_,c_,s_;
};

int  main()
{
    
/*
    freopen("data.in","r",stdin);
    freopen("data.out","w",stdout);
    //
*/

    
int  T( 0 ),n;
    
while (scanf( " %d " , & n) == 1   &&  n)
    {
        Type r[kMaxn];
        
for ( int  i = 1 ;i <= n;i ++ )
            scanf(
" %d%d%d%d " , & r[i].a_, & r[i].b_, & r[i].c_, & r[i].s_);

        
int  ans( - 1 );
        
for ( int  i = 1 ;i <= n;i ++ )
            
for ( int  j = 1 ;j <= n;j ++ )
                
for ( int  k = 1 ;k <= n;k ++ )
                {
                    
bool  used[ 10 ] = { false };
                    used[r[i].a_]
= true ;
                    used[r[i].b_]
= true ;
                    used[r[i].c_]
= true ;
                    used[r[j].a_]
= true ;
                    used[r[j].b_]
= true ;
                    used[r[j].c_]
= true ;
                    used[r[k].a_]
= true ;
                    used[r[k].b_]
= true ;
                    used[r[k].c_]
= true ;

                    
bool  success( true );
                    
for ( int  l = 1 ;l <= 9 ;l ++ )
                        
if ( ! used[l])
                        {
                            success
= false ;
                            
break ;
                        }

                    
if ( ! success)
                        
continue ;

                    ans
= max(ans,r[i].s_ + r[j].s_ + r[k].s_);
                }

        T
++ ;
        printf(
" Case %d: %d\n " ,T,ans);
    }

    
return   0 ;
}

你可能感兴趣的:(UVa 11218 KTV)