백준
1. DFS
import sys
input = sys.stdin.readline
n = int(input())
board = [list(map(int, input().split())) for _ in range(n)]
visit = [0] * n
result = sys.maxsize
def dfs(index, count):
global result
if count == n // 2:
start, link = 0, 0
for i in range(n):
for j in range(n):
if visit[i] and visit[j] and board[i][j] != 0:
start += board[i][j]
elif not visit[i] and not visit[j] and board[i][j] != 0:
link += board[i][j]
result = min(result, abs(start - link))
for i in range(index, n):
if visit[i]:
continue
visit[i] = 1
dfs(i + 1, count + 1)
visit[i] = 0
dfs(0, 0)
print(result)