03. Travelling Salesman Problem
β GFG solution to the Travelling Salesman Problem: find minimum cost to visit all cities exactly once and return to start using dynamic programming with bitmask optimization. π
π§© Problem Description
π Examples
Example 1
Input: cost[][] = [[0, 111],
[112, 0]]
Output: 223
Explanation: We can visit 0->1->0 and cost = 111 + 112 = 223.Example 2
Input: cost[][] = [[0, 1000, 5000],
[5000, 0, 1000],
[1000, 5000, 0]]
Output: 3000
Explanation: We can visit 0->1->2->0 and cost = 1000 + 1000 + 1000 = 3000.π Constraints
β
My Approach
Bitmask Dynamic Programming
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
β Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated