Dynamic Programming21 sections · 916 units
Open in Course

When Bitmask DP?

Recognition tips

Use bitmask DP (dynamic programming) when:

1.1. You need to track which elements from a small set (n20n \leq 20) have been used.

2.2. The problem involves permutations, matchings, or visiting all items.

3.3. Brute force is O(n!)O(n!) but O(2n)O(2^n) is acceptable. Signals: "visit all cities exactly once", "assign workers to tasks", "partition into subsets". If n>20n > 20, 2n2^n is too large. 22012^{20} \approx 1 million is fine. 225332^{25} \approx 33 million is borderline.