-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14889.py
More file actions
59 lines (38 loc) · 892 Bytes
/
Copy path14889.py
File metadata and controls
59 lines (38 loc) · 892 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
41
42
43
44
45
46
47
48
49
50
51
52
import sys
import copy
sys.setrecursionlimit(100000)
N = int(sys.stdin.readline())
board = []
for i in range(N):
board.append(list(map(int,sys.stdin.readline().split())))
used = [0] * N
answer = 1000000
chosen = [0] * N
def check_diff():
global answer
score_a = 0
score_b = 0
team_a = []
team_b = []
for i in range(N):
if chosen[i] == 1:
team_a.append(i)
else:
team_b.append(i)
for i in range(N//2):
for j in range(i+1,N//2):
score_a += (board[team_a[i]][team_a[j]] + board[team_a[j]][team_a[i]])
score_b += (board[team_b[i]][team_b[j]] + board[team_b[j]][team_b[i]])
answer = min(answer,abs(score_a-score_b))
def dfs(count,idx):
if count == N/2:
check_diff()
return
for i in range(idx,N):
if chosen[i]:
continue
chosen[i] = 1
dfs(count+1,i)
chosen[i] = 0
dfs(0,0)
print(answer)