Dynamic Programming21 sections · 916 units
Open in Course

Digit Set - The Setup

Understanding the constraints

You can only use digits from the given set. At each position, instead of trying 00-99, you try only the allowed digits. observation: numbers shorter than nn are always valid (if they use allowed digits).

A 2-digit number made from [1,3,5,7][1,3,5,7] is 100\leq 100. For numbers with the same length as nn, you need the tight bound logic. Can you place digit dd at position pospos without exceeding nn? Transform the problem: count valid numbers by building them digit by digit from left to right.