-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathO-Matching.cpp
More file actions
36 lines (30 loc) · 790 Bytes
/
Copy pathO-Matching.cpp
File metadata and controls
36 lines (30 loc) · 790 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
//Problem : https://atcoder.jp/contests/dp/tasks/dp_o
#include <bits/stdc++.h>
#define int long long
#define sz(x) (int)(x.size())
using namespace std;
const int N = 21, mod = 1e9 + 7;
int n, comp[N][N], dp[N][1 << N];
int go(int id, int taken){
if(id >= n)
return 1;
int &ways = dp[id][taken];
if(~ways)
return ways;
ways = 0;
for(int i = 0; i < n; i++) if((taken >> i & 1) == 0){
if(comp[id][i])
ways = (ways + go(id + 1, taken | (1 << i))) % mod;
}
return ways;
}
int32_t main(){
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
memset(dp, -1, sizeof(dp));
cin >> n;
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
cin >> comp[i][j];
cout << go(0, 0);
}