728x90
반응형
https://www.acmicpc.net/problem/14889
Python
from itertools import combinations
import sys
n = int(sys.stdin.readline().rstrip())
arr = []
for _ in range(n):
arr.append(list(map(int,sys.stdin.readline().split())))
combi = list(combinations([i for i in range(1,n+1)],n//2))
#print(combi)
result = 100000000
team = [ list(combinations(combi[i],2)) for i in range(len(combi))]
for i in range(len(team)):
#print(x)
start = team[i]
link = team[-i-1]
ssum = 0
for s in start:
ssum+= arr[s[0]-1][s[1]-1] + arr[s[1]-1][s[0]-1]
lsum = 0
for s in link:
lsum+= arr[s[0]-1][s[1]-1] + arr[s[1]-1][s[0]-1]
result = min(result, abs(ssum-lsum))
print(result)
728x90
반응형
'Algorithm Problems' 카테고리의 다른 글
[백준] [Python] 10799번 쇠막대기 (0) | 2021.05.22 |
---|---|
[백준] [Python] 2493번 탑 - 스택 - [대표예제] (0) | 2021.05.22 |
[백준] [Python] 14888번 연산자 끼워넣기 - 백트래킹 (0) | 2021.05.18 |
[백준] [Python] 1966번 프린터 큐 - 큐 (0) | 2021.05.16 |
[백준] [Python] 15655번 N과 M (6) - 백트래킹 - [대표예제] (0) | 2021.05.16 |