Official

F - Variety of Digits Editorial by en_translator


It can be solved with a technique called Digit DP (Dynamic Programming). It can be solved by

\(DP[i][S]=\) the number and the sum of the first \(i\) digits of integers whose the set of digits is \(S\) and that is less than \(N\)

Note that both the number and sum has to be managed. The complexity is \(O(2^B B \log_B N)\) where base \(B=10\).

Sample code (Python)

Rather basic digit DP problem: EDPC S『Digit Sum』

posted:
last update: