POJ 1014

POJ 1014
#include  < iostream >
#include 
< string .h >

using   namespace  std;

int  f[ 200001 ];
int  num[ 200001 ];

int  main()
{
    
int  v[ 7 ], test  =   0 ;
    
while (scanf( " %d " & v[ 1 ]))
    {
        memset(f,
0 , sizeof (f));
        
int  i, sum  =  v[ 1 ];
        
for (i  =   2 ; i  <=   6 ; i  ++
        {
            scanf(
" %d " & v[i]);
            sum 
+=  v[i]  *  i;
        }
        
if ( ! sum)  break ;
        printf(
" Collection #%d:\n " , ++  test);
        
if (sum  %   2 ) puts( " Can't be divided.\n " );
        
else
        {
            
int  k, j, c  =   0 ;
            f[
0 =   1 ;
            sum 
/=   2 ;
            
for (i  =   1 ; i  <=   6 ; i  ++ )
            
if (v[i])
            {
                
for (j  =  i; j  <=  sum; j  ++ )
                
if ( ! f[j]  &&  f[j - i]  &&  num[j - i]  <  v[i])
                {
                    f[j] 
=   1 ;
                    num[j] 
=  num[j - i]  +   1 ;
                    
if (f[sum])  break ;
                }
                
if (f[sum])  break ;
                
for (j  =  i; j  <=  sum; j  ++ ) num[j]  =   0 ;
            }
            
if (f[sum]) puts( " Can be divided.\n " );
            
else          puts( " Can't be divided.\n " );
        }
    }
}

你可能感兴趣的:(POJ 1014)