fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int md = 1e9 + 7;
  4. int n, cnt;
  5. vector<int> dp = {1};
  6. vector<vector<int>> check;
  7. int main()
  8. {
  9. ios::sync_with_stdio(0);
  10. cin.tie(0);
  11. cout.tie(0);
  12. freopen("matching.inp", "r", stdin);
  13. freopen("matching.out", "w", stdout);
  14. cin >> n;
  15. dp.resize(1 << n);
  16. check.resize(n, vector<int>(n));
  17. for (int i = 0; i < n; i++)
  18. for (int j = 0; j < n; j++)
  19. cin >> check[i][j];
  20. for (int mask = 1; mask < (1 << n); mask++)
  21. {
  22. cnt = __builtin_popcount(mask);
  23. for (int j = 0; j < n; j++)
  24. if (mask >> j & 1 && check[cnt - 1][j])
  25. (dp[mask] += dp[mask ^ (1 << j)]) %= md;
  26. }
  27. cout << dp.back();
  28. return 0;
  29. }
Success #stdin #stdout 0.01s 5308KB
stdin
Standard input is empty
stdout
Standard output is empty