Блог пользователя dario-dsa

Автор dario-dsa, 11 лет назад, По-английски

I have a problem with this task. http://www.spoj.com/problems/LINEUP/ It looks pretty easy but my solution fail. Can anyone help to figure it out? Thanks very much for any help. :-)

#include <cstdio>
#include <string.h>
using namespace std;

int n;
int prob[21][21];

char vec_rijesio[1<<13];
int memo[1<<13];
int rijesi( int d, int s ) {
   if ( d == 11 )
     {
       return 0;
     }
   if ( vec_rijesio[s] ) return memo[s];
   vec_rijesio[s] = 1;
   int &ret = memo[s];
   ret = 0;

   for ( int i=0; i<11; ++i )
      if ( ( s & (1<<i) ) == 0 ) {
         int tmp = prob[d][i] + rijesi(d + 1, s|(1<<i));
         if ( tmp > ret ) ret = tmp;
      }

   return ret;
}

int main() {
   scanf( "%d", &n );
   for(int o=0;o<n;++o)
   {
   for ( int i=0; i<11; ++i )
      for ( int j=0; j<11; ++j ) {
         int x;
         scanf( "%d", &x );
         prob[i][j] = x;
      }

   int ret = rijesi( 0, 0 );
   printf( "%d\n", ret);
   memset (memo,0,sizeof(memo));
   memset (vec_rijesio,0,sizeof(vec_rijesio));
   }
   return 0;
}
  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится