Dynamic Programming21 sections · 916 units
Open in Course

Special Integers - Transition

Checking the mask

At each position, try digits 00 to limitlimit (where limitlimit is 99 if not tight, else n[pos]n[pos]). For each digit dd:

1.1. If started and bit dd is set in mask: skip (digit already used).

2.2. If not started and d=0d = 0: recurse with started still false, mask unchanged.

3.3. Otherwise: recurse with started = true, new mask = mask | (1<<d)(1 << d). The mask grows as you place digits, blocking repeats. This formula shows how dp at position pos depends on dp at position pos+1.