-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patho-matching.py
More file actions
40 lines (35 loc) · 716 Bytes
/
o-matching.py
File metadata and controls
40 lines (35 loc) · 716 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
38
39
40
'''
n=int(input())
arr=[]
for _ in range(n):
l1=list(map(int,input().split()))
arr.append(l1)
dp=[0 for i in range(1<<n)]
dp[0]=1
for men in range((1<<n)-1):
setbits=bin(men).count('1')
for women in range(n):
if (arr[setbits][women] and (men&(1<<women))==0):
m2=men^(1<<women)
dp[m2]+=dp[men]
'''
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
M = 10 ** 9 + 7
cur = [0] * (1 << N)
cur[0] = 1
for B in A:
nxt = [0] * (1 << N)
C = [1 << i for i, v in enumerate(B) if v == 1]
print(c)
for s, v in enumerate(cur):
if v == 0:
continue
v %= M
for b in C:
if (s & b) != 0:
continue
nxt[s | b] += v
cur = nxt
print(cur[(1 << N) - 1] % M)
print(dp[(1<<n)-1])