728x90
반응형
1. 문제
2. 풀이
import sys
from itertools import permutations, combinations
num = int(sys.stdin.readline())
skill_matrix = []
for idx in range(num):
skill_matrix.append(list(map(int, sys.stdin.readline().split())))
players = list(range(num))
team_list = sorted(list(set(combinations(players,int(num/2)))))
total_gap = []
team_list_len = len(team_list)
min_gap = 10000000
for idx in range(int(team_list_len//2)) : # 절반만 탐색
# get now team combi score
now_combi = 0
now_team = team_list[idx]
for one_p in now_team:
for other_p in now_team:
now_combi += skill_matrix[one_p][other_p]
# get opposite team combi score
opp_combi = 0
now_opp_team = team_list[team_list_len - idx - 1] # opposite team
for one_p in now_opp_team:
for other_p in now_opp_team:
opp_combi += skill_matrix[one_p][other_p]
gap = abs(now_combi - opp_combi)
min_gap = min(min_gap, gap)
print(min_gap)
728x90
반응형
'Study > Algorithm & Data structure' 카테고리의 다른 글
[프로그래머스] [hash] 방문길이 python (201006) (0) | 2020.10.06 |
---|---|
[프로그래머스][heap] 게임아이템 python (201005) (0) | 2020.10.05 |
[백준] 톱니바퀴 python (201004) (0) | 2020.10.04 |
[프로그래머스][DP] 등굣길 python (201002) (0) | 2020.10.03 |
[프로그래머스] 없어진 기록 찾기 SQL - 200930 (0) | 2020.09.30 |
댓글