File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ import sys
2+
3+ input = sys .stdin .readline
4+ N = int (input ()) # 전체 인원
5+
6+ status = [list (map (int , input ().split ())) for _ in range (N )] # 능력치
7+
8+ visited = [False ] * N
9+ result = sys .maxsize # 결과 큰 수로 초기화
10+
11+
12+ def dfs (a , idx ):
13+ global result
14+
15+ if a == N // 2 : # 반반으로 나뉘었을 경우
16+
17+ # 각 팀의 능력치 초기화
18+ team_start = 0
19+ team_link = 0
20+
21+ for i in range (N ):
22+ for j in range (N ):
23+
24+ # 방문한 반을 start 팀으로 배정
25+ if visited [i ] and visited [j ]:
26+ team_start += status [i ][j ]
27+
28+ # 방문하지 않은 반을 link 팀으로 배정
29+ elif not visited [i ] and not visited [j ]:
30+ team_link += status [i ][j ]
31+
32+ result = min (result , abs (team_start - team_link ))
33+ return
34+
35+ else : # 인원 나누기
36+ for i in range (idx , N ):
37+ if not visited [i ]:
38+ visited [i ] = True
39+ dfs (a + 1 , i + 1 )
40+ visited [i ] = False
41+
42+
43+ dfs (0 , 0 )
44+ print (result )
You can’t perform that action at this time.
0 commit comments