Dynamic Programming21 sections · 916 units
Open in Course

Hamiltonian Flights - Problem Statement

Count routes, bitmask DP

You will solve CSES 1690 - Hamiltonian Flights. This is NOT the Traveling Salesman Problem (TSP).

The difference: TSP finds the minimum cost Hamiltonian cycle (visit all cities, return to start). CSES 1690 counts Hamiltonian paths from city 11 to city nn (visit all cities exactly once, fixed endpoints).

You'll use bitmask DP where dp[mask][i]dp[mask][i] = number of ways to visit the cities in 'mask' and end at city ii. The final answer is dp[(1<<n)1][n1]dp[(1<<n)-1][n-1] modulo 109+710^9+7.