At each position, try digits to (where is if not tight, else ). For each digit :
If started and bit is set in mask: skip (digit already used).
If not started and : recurse with started still false, mask unchanged.
Otherwise: recurse with started = true, new mask = mask | . The mask grows as you place digits, blocking repeats. This formula shows how dp at position pos depends on dp at position pos+1.