fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define all(x) (x).begin(),(x).end()
  4. #define sz(x) (int)(x).size()
  5. #define FOR(i,a,b) for(int i=(a);i<=(b);++i)
  6. #define FORD(i,a,b) for(int i=(a);i>=(b);--i)
  7. #define pb push_back
  8. #define fi first
  9. #define se second
  10. #define el "\n"
  11. typedef long long ll;
  12. const ll MOD=1e9+7,INF=1e18;
  13. int n,mai[21][21],dp[1<<21];
  14. void solve(){
  15. cin>>n;
  16. for (int i=0;i<n;i++)
  17. {
  18. for (int j=0;j<n;j++)
  19. {
  20. cin>>mai[i][j];
  21. }
  22. }
  23. dp[0]=1;
  24. int nm=(1<<n);
  25. for (int m=0;m<nm-1;m++)
  26. {
  27. if (dp[m]==0) continue;
  28. int i=__builtin_popcount(m);
  29. for (int j=0;j<n;j++)
  30. {
  31. if (mai[i][j]==1 and !(m&(1<<j)))
  32. {
  33. int nx=m|(1<<j);
  34. dp[nx]+=dp[m];
  35. }
  36. }
  37. }
  38. cout<<dp[nm-1]<<el;
  39. }
  40.  
  41. int main(){
  42. ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  43. int t=1;//cin>>t;
  44. while(t--)solve();
  45. return 0;
  46. }
  47.  
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
1