Advertisement
Guest User

Untitled

a guest
Oct 26th, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include <cstdio>
  2. #include <string.h>
  3. using namespace std;
  4.  
  5. int n;
  6. int prob[21][21];
  7.  
  8. char vec_rijesio[1<<13];
  9. int memo[1<<13];
  10. const int INF = 0x3f3f3f3f;
  11. int rijesi( int d, int s ) {
  12. if ( d == 11 )
  13. {
  14. return 0;
  15. }
  16. if ( vec_rijesio[s] ) return memo[s];
  17. vec_rijesio[s] = 1;
  18. int &ret = memo[s];
  19. ret = 0;
  20.  
  21. for ( int i=0; i<11; ++i )
  22. if ( ( s & (1<<i) ) == 0 ) {
  23. if(prob[d][i]!=0)
  24. {
  25. int tmp = prob[d][i] + rijesi(d + 1, s|(1<<i));
  26. if ( tmp > ret ) ret = tmp;
  27. }
  28. }
  29.  
  30. return ret;
  31. }
  32.  
  33. int main() {
  34. scanf( "%d", &n );
  35. for(int o=0;o<n;++o)
  36. {
  37. for ( int i=0; i<11; ++i )
  38. for ( int j=0; j<11; ++j ) {
  39. int x;
  40. scanf( "%d", &x );
  41. prob[i][j] = x;
  42. }
  43.  
  44. int ret = rijesi( 0, 0 );
  45. printf( "%d\n", ret);
  46. memset (memo,0,sizeof(memo));
  47. memset (vec_rijesio,0,sizeof(vec_rijesio));
  48. }
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement