-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10971.py
More file actions
28 lines (20 loc) · 678 Bytes
/
Copy path10971.py
File metadata and controls
28 lines (20 loc) · 678 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 외판원 순회 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 and weightList[now][start] != 0:
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
travelCity(start, i, count+1, sumWeight+weightList[now][i])
visited[i] = False
for i in range(N):
visited[i] = True
travelCity(i, i, 0, 0)
print(answer)