[백준] 14889번 : 스타트와 링크(파이썬)

서봉성·2023년 5월 28일
0

코딩테스트

목록 보기
15/27

문제

https://www.acmicpc.net/problem/14889

코드

n=int(input())
scores=[list(map(int, input().split())) for _ in range(n)]

selects=[0]*(n//2)
ans=99999999

def check():
    st, link=0, 0
    another=[]
    for i in range(n):
        if i not in selects:
            another.append(i)
            
    for i in selects:
        for j in selects:
            st+=scores[i][j]
    
    for i in another:
        for j in another:
            link+=scores[i][j]
    return abs(st-link)

def back(index, start):
    if index==(n//2):
        global ans
        ans=min(ans, check())
        return
    
    for i in range(start, n):
        selects[index]=i
        back(index+1, i+1)
        
back(0, 0)
print(ans)
profile
OverStudy

0개의 댓글