ν°μ€ν 리 λ·°
λ¬Έμ
λ¬Έμ νμ΄
μμ νΌ λ¬Έμ λ€μ (15650 Nκ³Ό M (2), 1759 μνΈ λ§λ€κΈ°) μ‘°ν©μ ꡬνκ±°λ, μ‘°ν©μ λ§μ‘±νλ κ²½μ°λ₯Ό μ°Ύλ λ¬Έμ μλ€. μ΄ λ¬Έμ μμλ μ‘°ν©μ μμ°¨μ μΌλ‘ ꡬνκ² λλ©΄ λμΉλλ μ±μ§μ νμ©νλ λ¬Έμ μ΄λ€. μλ₯Ό λ€μ΄ μμ μ λ ₯1μ λλ μ μλ μ‘°ν©μ μμ°¨μ μΌλ‘ λμ΄νλ©΄ [0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3]μ΄λ€. μ¬κΈ°μ μ μ μλ κ²μ [0, 1], [0, 2], [0, 3] [1, 2], [1, 3], [2, 3] μ κ°μ΄ (μ‘°ν©[i], μ‘°ν© [μ‘°ν©μ μ -i - 1])κ° νλμ κ²½μ°μ μλ₯Ό λ§μ‘±νλ€λ κ²μ μ μ μλ€.
λ°λΌμ λ¬Έμ λ λ€μκ³Ό κ°μ΄ ν΄κ²°ν μ μλ€.
-
Nμ λ°λ₯Έ νμ μ‘°ν©μ DFSλ₯Ό ν΅ν΄ ꡬνλ€.
-
μμ λ§ν μ‘°ν©μ΄ λμΉλλ μ±μ§μ μ΄μ©νμ¬, μ€ννΈ, λ§ν¬ νμ λν λ₯λ ₯μΉλ₯Ό κ³μ°νλ€.
-
μ°¨κ° κ°μ₯ μμ κ²½μ°λ₯Ό λ°ννλ€.
μ½λ
from sys import stdin
def dfs(idx, depth):
if depth == n // 2:
case.append([*check])
return
for i in range(idx, n):
if not i in check:
check[depth] = i
dfs(i, depth + 1)
check[depth] = -1
def team_ability(idx):
sum_ability = 0
team = case[idx]
for player in team:
for other_player in team:
if other_player == player:
continue
sum_ability += ability[player][other_player]
return sum_ability
if __name__ == '__main__':
case = []
answer = 10 ** 7
n = int(stdin.readline())
idx = [i for i in range(n)]
ability = [list(map(int, stdin.readline().split())) for _ in range(n)]
check = [-1] * (n // 2)
dfs(0, 0)
print(case)
for i in range(len(case) // 2):
answer = min(answer, abs(team_ability(i) - team_ability(-i-1)))
print(answer)
νμ λ₯λ ₯μΉλ₯Ό κ³μ° ν λ, if other_player == player
λ μλ΅ν΄λ μκ΄ μλ€. i, jκ° κ°μ κ²½μ°λ 0μ΄κΈ° λλ¬Έμ΄λ€.
'π¨βπ» μ½λ©ν μ€νΈ > λ°±μ€' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
λ°±μ€: 1248 λ§μΆ°λ΄ (0) | 2020.07.19 |
---|---|
λ°±μ€: 2529 λΆλ±νΈ (0) | 2020.07.18 |
λ°±μ€: 1759 μνΈ λ§λ€κΈ° (0) | 2020.07.17 |
λ°±μ€: 14501 ν΄μ¬ (0) | 2020.07.16 |
λ°±μ€: 10971 μΈνμ μν 2 (0) | 2020.07.16 |