Most digit DP problems use this state: : current digit position (0 to length-1, left to right). : are we still bounded by ? : have we placed a non-zero digit yet? : problem-specific state (used digits, digit sum, remainder, etc.).
To compute dp, try each valid digit at , updates the state, and recurses. Base case: when equals the length, return if valid, otherwise.