-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkey.py
More file actions
31 lines (29 loc) · 902 Bytes
/
key.py
File metadata and controls
31 lines (29 loc) · 902 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
from itertools import combinations
def solution(relation):
N = len(relation)
CN = len(relation[0])
if CN == 1:
return 1
unique = []
idxs = [i for i in range(CN)]
# 유일성 검증
for n in range(1, N+1):
for r in combinations(idxs, n):
sets = []
for row in relation:
sets.append(''.join([row[i] for i in range(CN) if i in r]))
sets = set(sets)
if len(sets) == N:
unique.append(r)
answer = []
unique = list(reversed(unique))
while unique:
element = unique.pop()
answer.append(element)
del_list = []
for other_element in unique:
if set(element).issubset(set(other_element)):
del_list.append(other_element)
for del_element in del_list:
unique.remove(del_element)
return len(answer)