백준 문제 풀이
백준 14889 파이썬 python : 스타트와 링크 @@황소처럼 우직하게@@
hjp845
2020. 2. 27. 00:34
반응형
import sys
input = sys.stdin.readline
n = int(input())
mat = []
for i in range(n):
mat.append(list(map(int, input().strip().split())))
import itertools
gab = 999999999
team = [i for i in range(n)]
tt = list(itertools.combinations(team, n // 2))
for team1 in tt:
team2 = [x for x in team if x not in team1]
team1_score = 0
team2_score = 0
for x, y in list(itertools.combinations(team1, 2)):
team1_score += mat[x][y] + mat[y][x]
for x, y in list(itertools.combinations(team2, 2)):
team2_score += mat[x][y] + mat[y][x]
gab = min(gab, abs(team1_score - team2_score))
print(gab)
모든 경우의 수에 대하여 고려해봅시다.
콤비네이션으로 모든 팀의 경우의 수를 구하고, 각 팀에서 2명씩 콤비네이션으로 뽑아내서 비교해주기.
채점하는데 몇분걸렸다;;
반응형