Given a huge integer N, you can use the dynamic programming algorithm to count up the number of things that satisfy the condition from non-negative integers less than or equal to N.
Example of my implementation
DP S An integer between 1 and K, where the sum of each digit in decimal notation is a multiple of D.
ABC154E An integer greater than or equal to 1 and less than or equal to N and exactly K non-zero numbers when expressed in decimal notation.
Use the information about the upper i digits to find the information for i+1 digits
python
for k in range(K + 1):
new_less[k] += less[k] # for 0
new_less[k + 1] += 9 * less[k] # for 1..9
The only exception is when the upper i digits match N
If the last case matching N satisfies the condition, answer +1.
If implemented naturally, the value is for "integers greater than or equal to 0", so depending on the problem conditions, the case of 0 is subtracted.
https://maspypy.com/atcoder-参加感想-2019-02-16abc-155
This page is auto-translated from /nishio/桁DP using DeepL. If you looks something interesting but the auto-translated English is not good enough to understand it, feel free to let me know at @nishio_en. I'm very happy to spread my thought to non-Japanese readers.