We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d7134b0 commit 1a0dd31Copy full SHA for 1a0dd31
dynamic_programming/travelling_sales_person.py
@@ -30,13 +30,13 @@ def travelling_salesman(cost_matrix: list[list[int]]) -> float:
30
represents the cost of traveling from city i to city j.
31
32
Returns:
33
- int: The minimum total cost of the tour.
+ float: The minimum total cost of the tour.
34
"""
35
n = len(cost_matrix)
36
all_visited = (1 << n) - 1 # bitmask with all cities visited
37
38
@functools.cache
39
- def dp(mask: int, pos: int) -> int:
+ def dp(mask: int, pos: int) -> float:
40
# Base case: all cities visited, return cost to go back to start
41
if mask == all_visited:
42
return cost_matrix[pos][0]
0 commit comments