Skip to content

Commit

Permalink
[#12] Feat: Add 외판원 순회 2
Browse files Browse the repository at this point in the history
  • Loading branch information
letsjo committed Apr 12, 2023
1 parent 8e37d4f commit c472707
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions 10971.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 외판원 순회 2

N = int(input())
weightList = [list(map(int, input().split())) for _ in range(N)]
visited = [False for _ in range(N)]

answer = float('inf')


def travelCity(start, now, count, sumWeight):
global answer
if (N == count+1):
sumWeight += weightList[now][start]
answer = min(answer, sumWeight)
return

for i in range(N):
if not visited[i] and weightList[now][i] > 0:
visited[i] = True
sumWeight += weightList[now][i]
travelCity(start, i, count+1, sumWeight)
visited[i] = False
sumWeight -= weightList[now][i]


for i in range(N):
visited[i] = True
travelCity(i, i, 0, 0)

print(answer)

0 comments on commit c472707

Please sign in to comment.