fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. using ll=long long;
  4.  
  5. const int maxn=100005;
  6. const ll inf=1e15;
  7.  
  8. bool A[20][20];
  9. ll n,f[1050006][20];
  10. void solve()
  11. {
  12. memset(f,0,sizeof f);
  13. cin>>n;
  14. for(int i=0; i<n; i++)
  15. for(int j=0; j<n; j++)
  16. cin>>A[i][j];
  17. for(int i=0;i<n;i++)
  18. f[0][i]=1;
  19. for(int mask=0;mask<(1<<n);mask++)
  20. {
  21. int k=__builtin_popcount(mask);
  22. if(k==n) continue;
  23. for(int i=0;i<n;i++)
  24. {
  25. if(A[i][k] && ((mask&(1<<i))==0))
  26. {
  27. f[mask|(1<<i)][k+1]+=f[mask][k];
  28. }
  29. }
  30. }
  31. cout<<f[(1<<n)-1][n]<<'\n';
  32.  
  33. }
  34. int main()
  35. {
  36. int test;
  37. cin>>test;
  38. while(test--)
  39. solve();
  40. }
  41.  
Success #stdin #stdout 0.01s 5328KB
stdin
Standard input is empty
stdout
Standard output is empty