TSP with Bitmask DP

Hard

📝 Description

Solve the Traveling Salesman Problem using DP with bitmasking.

Input Format

[[w11, w12, ...], ...] (n x n cost matrix)

Output Format

minimum cost (integer)

Constraints

2 ≤ n ≤ 20

🔍 Sample Input

[[0, 10, 15, 20], [10, 0, 35, 25], [15, 35, 0, 30], [20, 25, 30, 0]]
            

✅ Sample Output

80
            

Code Editor

Please login to run and submit code.

Shortcuts: Ctrl+Enter to submit, Ctrl+Shift+R to run