https://www.acmicpc.net/problem/14889
14889번: 스타트와 링크
예제 2의 경우에 (1, 3, 6), (2, 4, 5)로 팀을 나누면 되고, 예제 3의 경우에는 (1, 2, 4, 5), (3, 6, 7, 8)로 팀을 나누면 된다.
www.acmicpc.net
import sys
input = sys.stdin.readline
def update():
global ret
team1,team2 = 0,0
for i in range(a):
for j in range(a):
if pick[i] and pick[j]:
team1 += b[i][j]
elif not pick[i] and not pick[j]:
team2 += b[i][j]
ret = min(ret,abs(team1-team2))
def solution(cur,pick_count):
if pick_count ==a//2:
update()
return
for i in range(cur,a):
pick[i]=1
solution(i+1,pick_count+1)
pick[i]=0
a = int(input())
b=[list(map(int,input().split())) for _ in range(a)]
pick=[0] * a
ret=1e9
solution(0,0)
print(ret)
'취준 > 백준' 카테고리의 다른 글
9184 - 파이썬 (0) | 2022.05.03 |
---|---|
1003 - 파이썬 (0) | 2022.05.03 |
14888 - 파이썬 (0) | 2022.05.01 |
15650 - 파이썬 (0) | 2022.04.05 |
15649 - 파이썬 (0) | 2022.04.05 |