Define = count of valid numbers using positions to end, given whether we're tight. No "started" flag needed here because all digits in the set are non-zero (the problem guarantees digits are from -).
Every number we form is positive. The answer is the sum of: (1) all numbers shorter than , plus (2) for numbers with the same length as . This state captures all the information needed to count valid numbers from position pos onward.