# Number of ways to form distinctive number given sum of digits

We are given sum of digits M and maximum number of decimal places N.
We have to find the count of number that can be formed such the the sum of digits is M and the consecutive digit of the number should not be less than the previous digit for example:-

• If M = 5 and N = 2 Possible numbers that can be formed are:- 05,14,23
Hence count=3

• If M = 3 and N = 3 Possible numbers that can be formed are:- 003,012,111
Hence count=3

• If M = 6 and N = 3 Possible numbers that can be formed are:- 006,015,024,033,114,123,222
Hence count=7

• This is the number of partitions of $M$ into at most $N$ parts. Look at en.wikipedia.org/wiki/… Wait, maybe not. Are the digits restricted to being $\le9?$ Then what I said would not be correct. It would be the number of partitions on $M$ in at most $N$ parts not exceeding $9$. – saulspatz Jul 24 '18 at 20:43
• @packetpacket No, in a partition the summands are ordered. – saulspatz Jul 24 '18 at 20:47
• @packetpacket No, 5-8-5 and 5-5-8 are the same partition You are thinking of compositions – saulspatz Jul 24 '18 at 20:54
• @saulspatz My bad, I understand now. – packetpacket Jul 24 '18 at 20:58