-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathO.cpp
More file actions
36 lines (31 loc) 路 742 Bytes
/
Copy pathO.cpp
File metadata and controls
36 lines (31 loc) 路 742 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
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<long long>;
ll n;
ll mod = 1e9 + 7;
ll MAX = 1e9;
const int N = 21;
ll dp[N][1 << N];
ll v[N][N];
int ways(int node, int mask)
{
if (mask == (1 << n) - 1) return 1;
if (dp[node][mask] != -1) return dp[node][mask];
ll ans = 0;
for (int j = 0; j < n; j++)
{
if (mask & (1 << j)) continue;
if (v[node][j] == 0) continue;
ans = (ans + ways(node + 1, mask | (1 << j))) % mod;
}
dp[node][mask] = ans;
return ans;
}
int main() {
cin >> n;
for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> v[i][j];
memset(dp, -1, sizeof(dp));
cout << ways(0, 0) << endl;
return 0;
}