-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatDPO.cpp
More file actions
37 lines (29 loc) · 789 Bytes
/
Copy pathatDPO.cpp
File metadata and controls
37 lines (29 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
* Contest : AtCoder Educational DP Contest
* Problem : O - Matching
* Link : https://atcoder.jp/contests/dp/tasks/dp_o
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
int main() {
fastio
int n, mod = 1e9+7;
cin >> n;
bool grid[n][n];
vector <int> dp(1 << n);
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
cin >> grid[i][j];
dp[0] = 1;
for (int mask = 0; mask < (1 << n); ++mask) {
int row = __popcount((unsigned int)mask);
for (int i = 0; i < n; ++i) {
if (mask & (1 << i) || !grid[row][i]) continue;
dp[mask | (1 << i)] = (dp[mask | (1 << i)] + dp[mask]) % mod;
}
}
cout << dp[(1 << n) - 1] << '\n';
return 0;
}