fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <cstdlib>
  4. #include <cstdio>
  5. #include <string.h>
  6. using namespace std;
  7. map<long long,long long>result;
  8. int main()
  9. {
  10. int t;
  11. scanf("%d",&t);
  12. for (;t>0;t--){
  13. int k;
  14. scanf("%d",&k);
  15. bool adj[k+1][k+1];
  16. for (int c(0);c<k;c++)
  17. for (int c1(0);c1<k;c1++)
  18. {int temp;scanf("%d",&temp);adj[c][c1]=temp;}
  19.  
  20. result[0]=1;
  21.  
  22. for (long long int c(1);c<(1<<k);c++){
  23. result[c]=0;
  24. int bitss(0);
  25. for (int b(1);b<=c;b=(b<<1))if ((c&b)==b)bitss++;
  26.  
  27. for (int c1(0);c1<k;c1++){
  28. if (adj[bitss-1][c1]&&(c&(1<<c1))==(1<<c1))result[c]=result[c]+result[c&(~(1<<c1))];
  29.  
  30. }
  31.  
  32.  
  33. }
  34. printf("%lld\n",result[(1<<k)-1]);
  35. }
  36. return 0;
  37. }
  38.  
  39.  
Success #stdin #stdout 0.01s 3484KB
stdin
3
3
1 1 1
1 1 1
1 1 1
11
1 0 0 1 0 0 0 0 0 1 1 
1 1 1 1 1 0 1 0 1 0 0 
1 0 0 1 0 0 1 1 0 1 0 
1 0 1 1 1 0 1 1 0 1 1 
0 1 1 1 0 1 0 0 1 1 1 
1 1 1 0 0 1 0 0 0 0 0 
0 0 0 0 1 0 1 0 0 0 1 
1 0 1 1 0 0 0 0 0 0 1 
0 0 1 0 1 1 0 0 0 1 1 
1 1 1 0 0 0 1 0 1 0 1 
1 0 0 0 1 1 1 1 0 0 0 
11
0 1 1 1 0 1 0 0 0 1 0 
0 0 1 1 1 1 1 1 1 1 1 
1 1 0 1 0 0 0 0 0 1 0 
0 1 0 1 0 1 0 1 0 1 1 
1 0 0 1 0 0 0 0 1 0 1 
0 0 1 0 1 1 0 0 0 0 1 
1 0 1 0 1 1 1 0 1 1 0 
1 0 1 1 0 1 1 0 0 1 0 
0 0 1 1 0 1 1 1 1 1 1 
0 1 0 0 0 0 0 0 0 1 1 
0 1 1 0 0 0 0 0 1 0 1 
stdout
6
7588
7426