Dynamic Programming21 sections · 916 units
Open in Course

Section Recap

What we learned

You learned Bitmask DP for subset-based states.

1.1. A bitmask represents a subset as an integer. Bit ii set means element ii is included. This compresses exponential state spaces into manageable O(2n)O(2^n).

2.2. TSP (Traveling Salesman Problem)-style problems need dp[mask][last]dp[\text{mask}][\text{last}]: which cities visited, which city you're at. Assignment problems often need just dp[mask]dp[\text{mask}].

3.3. SOS DP handles subset aggregation in O(n2n)O(n \cdot 2^n). Process one bit at a time, building from smaller flexibility to full subset sums.

When n20n \leq 20 and track subsets, think bitmask. The exponential state space is tractable for small nn.