fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5. const int MAX = 110;
  6. const int mod = 1e9 + 7;
  7.  
  8. int add(int a,int b){
  9. if(a+b < mod) return a+b;
  10. return a + b -mod;
  11. }
  12.  
  13.  
  14. int n,a[30][30], dp[1<<22][22];
  15.  
  16. int main(){
  17.  
  18. cin >> n;
  19. for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> a[i][j];
  20. dp[0][0] = 1;
  21.  
  22. for(int i = 1; i <= n; i++){
  23. for(int mask = 0; mask < (1<<n); mask++){
  24. for(int j = 0 ; j < n; j++){
  25. if( i != __builtin_popcount(mask)) continue;
  26. if(a[i-1][j] && (mask & 1<<j) ){
  27. dp[mask][i] = add(dp[mask][i], dp[mask^(1<<j)][i-1]);
  28. }
  29. }
  30. }
  31. }
  32. cout << dp[ (1<<n) -1][n] << endl;
  33. return 0;
  34. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
1