티스토리 뷰
https://www.acmicpc.net/problem/14889
import sys
from itertools import combinations
N = int(sys.stdin.readline())
s = []
for _ in range(N):
s.append(list(map(int, sys.stdin.readline().split())))
people = [i for i in range(N)]
com_people = list(combinations(people, N//2))
length = len(com_people)//2
com = com_people[0:length]
res = 100
for i in range(length):
check = [0] * N
temp1 = 0
temp2 = 0
for j in range(N//2):
check[com[i][j]] = 1
for k in range(N//2):
if j != k:
temp1 += s[com[i][j]][com[i][k]]
remain = []
for j in range(N):
if check[j] == 0:
remain.append(j)
for j in range(N//2):
for k in range(N//2):
if j != k:
temp2 += s[remain[j]][remain[k]]
res = min(res, abs(temp1 - temp2))
print(res)
'Algorithm > Baekjoon' 카테고리의 다른 글
[백준] 9251 : LCS - Python (0) | 2020.06.27 |
---|---|
[백준] 15686 : 치킨 배달 - Python (1) | 2020.06.24 |
[백준] 6064 : 카잉 달력 - Python (0) | 2020.04.25 |
[백준] 6603 : 로또 - Python (0) | 2020.04.24 |
[백준] 11724 : 연결 요소의 개수 - Python (0) | 2020.04.23 |