1
$\begingroup$

Say that I'm buying cakes for a party. I wish to buy $k$ cakes, and there are $n$ different kinds of cake, but only $m_i$ of each kind of cake (where $i$ denotes the $i$th kind). How many different combinations of cakes could I buy?

Context: I need to find the number of 4-character selections of "POSSESSES". Enumerating all of them gives me the expected result of 12, but I'd like a more... general solution for future reference.

  • 0
    A [similar question](https://stackoverflow.com/questions/53270489/how-can-we-count-the-r-combinations-of-a-multiset) arose at Stack Overflow, and I posted an algorithmic solution there. The original question there required a constraint on *r* (it is half the sum of the m[i]), but the code includes a routine that can solve for any *r*.2018-11-12

2 Answers 2