frp

SPOJ_423

frp
Aug 22nd, 2011
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. long long r[1 << 20][21];
  4. int m[20][20];
  5. void test()
  6. {
  7.     int n;
  8.     cin >> n;
  9.     for(int i = 0; i < (1 << n); i++)
  10.         for(int j = 0; j < n; j++)
  11.             r[i][j] = 0;
  12.     for(int i = 0; i < n; i++)
  13.         for(int j = 0; j < n; j++)
  14.             cin >> m[i][j];
  15.     r[0][0] = 1;
  16.     for(int j = 1; j <= n; j++)
  17.         for(int i = 0; i < (1 << n); i++)
  18.         {
  19.             r[i][j] = 0;
  20.             for(int l = 0; l < n; l++)
  21.                 if(m[l][j - 1] && i & (1 << l))
  22.                     r[i][j] += r[i ^ (1 << l)][j - 1];
  23.         }
  24.     cout << r[(1 << n) - 1][n] << '\n';
  25. }
  26. int main()
  27. {
  28.     int c;
  29.     cin >> c;
  30.     for(int i = 0; i < c; i ++)
  31.         test();
  32. }
Advertisement
Add Comment
Please, Sign In to add comment