[백준] 14889번 스타트와 링크 (파이썬, 완전탐색)
728x90
반응형
14889번: 스타트와 링크
예제 2의 경우에 (1, 3, 6), (2, 4, 5)로 팀을 나누면 되고, 예제 3의 경우에는 (1, 2, 4, 5), (3, 6, 7, 8)로 팀을 나누면 된다.
www.acmicpc.net
from collections import deque
from itertools import combinations
import math
n=int(input())
a=[list(map(int,input().split())) for _ in range(n)]
p=[i for i in range(n)]
allcase=combinations(p,n//2)
ans=math.inf
def check(start):
global ans
link=[]
for i in range(n):
if i not in start:
link.append(i)
sum,sum2=0,0
for i in range(n//2):
for j in range(n//2):
if i==j: continue
sum+=a[start[i]][start[j]]
sum2+=a[link[i]][link[j]]
if ans>abs(sum-sum2):
ans=abs(sum-sum2)
for case in allcase:
check(list(case))
print(ans)
728x90
반응형
'백준' 카테고리의 다른 글
[11053번] 가장 긴 증가하는 부분 수열 (python, bisect) (0) | 2020.11.23 |
---|---|
[백준] 15685번 드래곤커브 (python, 시뮬레이션) (0) | 2020.10.18 |
[백준] 14505번 연구소 (bfs, 시뮬레이션, 파이썬) (0) | 2020.10.17 |
[백준] 15686번 치킨배달 (시뮬, bfs, 파이썬, java) (0) | 2020.10.17 |
[백준] 14503번 로봇 청소기 (bfs, 시뮬레이션, python) (0) | 2020.10.17 |
TAGS.