## How many $20$ digit numbers $n$ (without any leading zero) exist such that no three consecutive digits of $n$ have a sum greater than $9$?

### To generate a solution, we will need to look for a pattern by applying dynamic programming techniques.

1. Consider the number of valid k-digit numbers for some integer k ending with any digit d for 0 ≤ d ≤ 9. For example, two-digit numbers ending with “1” would be “01”, “21”, “31”, etc.

2. Let’s denote F(k, d, s) as the count of k-digit numbers ending with a digit d and having sum of last two digits as s. It’s clear that F(2, d, s) = 1 for 1 ≤ d ≤ min(9, s) because there is obviously 1 two-digit number ending with d and having the sum of its 2 digits equal to s.

3. To find a recurrence, we consider the last but one digit. It can range from 0 to 9 – s, inclusive. If d’ is this number, then there are F(k – 1, d’, d + d’) such numbers of length k.

So, to generate numbers of greater length, we can iterate over k from 3 to 20 and over d from 0 to 9, then for each k and d, iterate over s from 1 to 9 and over d’ from 0 to min(s – 1, 9) to calculate F(k, d, s) = F(k, d, s) + F(k – 1 , d’, d + d’)

The solution is then the sum of F(20, d, s) for all possible d and s.

The idea behind this approach is that at each step, we are considering the valid numbers possible based on the last digit of current number and the sum of the last two digits. Using these values, we determine the number of possibilities for the next digit and hence, generate all the possible 20-digit numbers. Please note that the 3rd dimension is not really the sum, but the sum modulo 10, since we don’t really care if the sum is say 11 or 1, in our case it indicates the same thing, that the sum of these 3 digits exceeds 9 or not. This also saves a lot of memory.

This problem involves a variety of mathematics problem-solving skills, including understanding the decimal number system, applications of counting principles, and the utilization of dynamic programming concepts for efficient computation.

##### More Answers:

TriominoesHexadecimal Numbers

Cross-hatched Triangles