At position pos:
1. You can always place 0. Recurse with prev = 0.
2. You can place 1 only if prev =1 and (not tight or n[pos]=1). If prev was 1 and you try to place 1, you'd create 11. Skip that branch. The tight logic works the same as base 10: if tight and n[pos]=0, you can't place 1. This formula tells you how to compute dp(pos, tight, prev) from dp values at later positions. Getting this right is the core of DP.