0

This problem is close to a standard problem: the number of ways of adding up non-negative integers to form a given fixed number $M$.

However in this case there are two constraints: 1) each of the summands has to be strictly greater than 0, and 2) the total number of summands is fixed at length $k$.

  • for $k=1$ the answer is easy, 1
  • for $k=2$ the answer is 2(sum from 1 to floor(M/2)).

So obviously that's enough to create a recursive algorithm that would allow one to calculate the answer to the question for any specific values of M and k, but I'm wondering if there is any closed form solution for arbitrary $M$ and $k$?

Another way to express this is the number of partitions of a non-empty set of finite cardinality $M$ where the number of parts (or blocks) in each partition is a fixed value $k$.

String
  • 18,395
  • What does '2(sum from 1 to floor(M/2))' mean? And should order matter so that $1+2+3=6$ and $1+3+2=6$ constitute two distinct solutions to $M=6,k=3$? – String May 17 '18 at 22:44

2 Answers2

1

It appears from your second example that the order of summation matters (1+2 and 2+1 are distinct). In that case, consider the summands as k bins that you have to fill with M objects. It is clearly a combinations-with-repetition problem. Remember to reduce M by k, denoting how you took care not to leave any bins empty.

George K
  • 492
1

This is precisely the stars and bars algorithm. You have $M$ stars and $M-1$ places to put bars between them. Each of your integers is the number of stars between neighboring bars. You need to place $k-1$ bars to get $k$ blocks of stars, so there are $$M-1 \choose k-1$$ ways to do it.

Ross Millikan
  • 374,822
  • Thanks! I realized after I posted the question how to figure it out, but I still appreciate the answer. I did a bunch of searching before posting, but didn't find the right way of asking the question apparently, because today I found the right answer easily. Thanks again! – Michael Cloud May 18 '18 at 19:56
  • There are a number of problems that have classic solutions but with names that are not obviously related. If you know the name it is easy to search, but if you don't it can be impossible. This is one. – Ross Millikan May 19 '18 at 01:06