Skip to content

Commit 32f76b3

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent a1bd736 commit 32f76b3

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

dynamic_programming/travelling_salesman_problem.py

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def tsp(distances: list[list[int]]) -> int:
3232
# Memoization table
3333
memo = [[-1] * (1 << n) for _ in range(n)]
3434
visited_all = (1 << n) - 1 # All cities visited mask
35+
3536
def visit(city: int, mask: int) -> int:
3637
"""Recursively calculates the minimum cost to visit all cities."""
3738
if mask == visited_all:
@@ -47,7 +48,10 @@ def visit(city: int, mask: int) -> int:
4748
min_cost = min(min_cost, new_cost)
4849
memo[city][mask] = int(min_cost) # Store result as an integer
4950
return memo[city][mask] # Return the cached result
51+
5052
return visit(0, 1) # Start from city 0 with city 0 visited
53+
54+
5155
if __name__ == "__main__":
5256
import doctest
5357

0 commit comments

Comments
 (0)