Create a DP based solution to calculate sum of at most k digits that sum to n.
F(k,n) = sum_i F(k-1, n-i)
Assume your max has k digits and the most significant digit is sig(max) and dropsig(max) is the number without the most significant digit.
G(k,max,n) = F(k-1, n)+ G(k-1, dropsig(max), n-sig(max) ) + sum_i (k-1, n-i) for i = 1 to sig(max) -1 .
Obviously, you have to take care of corner cases. But here is the summary.
The first component corresponds to cases where the length of the numbers are less than the length of maximum number.
The second component corresponds to cases where the most significant digit of solution is same as the maximum significant digit of the max.
The third component corresponds to cases where most significant digit of the solution is less than significant digit of the max, but greater than or equal to 1.