def solution(N,MAPS):
    stack=list()
    answer=list()
    minscore=99999
    for i in range(N):
        stack.append((i,[i],MAPS[0][i],1))
        while stack:
            position, visited, score, idx=stack.pop()
            #백트래킹 조건
            if score>minscore:
                continue
            else:
                if len(visited)==N:
                    if minscore>score:
                        answer.append(score)
                        minscore=score
                    continue
                else:
                    for j in range(N):
                        if j not in visited:
                            stack.append((j,visited+[j],score+MAPS[idx][j],idx+1))
    return min(answer)
solution(3,[[73, 21, 21,],
[11, 59, 40,],
[24, 31, 83]])
a18cd1bc7820c4dcdbb5474324a539dc288cc7f0
<mask token>

def solution(N, MAPS):
    stack = list()
    answer = list()
    minscore = 99999
    for i in range(N):
        stack.append((i, [i], MAPS[0][i], 1))
        while stack:
            position, visited, score, idx = stack.pop()
            if score > minscore:
                continue
            elif len(visited) == N:
                if minscore > score:
                    answer.append(score)
                    minscore = score
                continue
            else:
                for j in range(N):
                    if j not in visited:
                        stack.append((j, visited + [j], score + MAPS[idx][j
                            ], idx + 1))
    return min(answer)


<mask token>

def solution(N, MAPS):
    stack = list()
    answer = list()
    minscore = 99999
    for i in range(N):
        stack.append((i, [i], MAPS[0][i], 1))
        while stack:
            position, visited, score, idx = stack.pop()
            if score > minscore:
                continue
            elif len(visited) == N:
                if minscore > score:
                    answer.append(score)
                    minscore = score
                continue
            else:
                for j in range(N):
                    if j not in visited:
                        stack.append((j, visited + [j], score + MAPS[idx][j
                            ], idx + 1))
    return min(answer)


solution(3, [[73, 21, 21], [11, 59, 40], [24, 31, 83]])

def solution(N,MAPS):
    stack=list()
    answer=list()
    minscore=99999
    for i in range(N):
        stack.append((i,[i],MAPS[0][i],1))
        while stack:
            position, visited, score, idx=stack.pop()
            #백트래킹 조건
            if score>minscore:
                continue
            else:
                if len(visited)==N:
                    if minscore>score:
                        answer.append(score)
                        minscore=score
                    continue
                else:
                    for j in range(N):
                        if j not in visited:
                            stack.append((j,visited+[j],score+MAPS[idx][j],idx+1))
    return min(answer)
solution(3,[[73, 21, 21,],
[11, 59, 40,],
[24, 31, 83]])