Dynamic Programming21 sections · 916 units
Open in Course

Lessons from Consecutive Ones

summary

1.1. Digit DP works in any base. Binary is just base 22 with digits 00 and 11.

2.2. Track the previous digit when constraints involve adjacent positions.

3.3. The dp table is tiny in binary: O(logn×2×2)O(\log n \times 2 \times 2) states. Binary digit DP appears in problems about binary representations, XOR constraints, and bit manipulation combined with counting. Apply these patterns when you encounter similar problems.