I'm looking to figure out the formula for putting K balls in N urns, where each of the N urns has a specific max capacity. For example,
- Urn A has capacity for at most 5 balls
- Urn B has capacity for at most 2 balls
- Urn C has capacity for at most 1 ball
- Urn D has capacity for at most 2 balls
How many ways are there to put 5 indistinguishable balls in urns A, B, C and D?
With brute-force code, I know that this example has these 18 solutions:
(0, 2, 1, 2) (1, 1, 1, 2) (1, 2, 0, 2) (1, 2, 1, 1) (2, 0, 1, 2) (2, 1, 0, 2) (2, 1, 1, 1) (2, 2, 0, 1) (2, 2, 1, 0) (3, 0, 0, 2) (3, 0, 1, 1) (3, 1, 0, 1) (3, 1, 1, 0) (3, 2, 0, 0) (4, 0, 0, 1) (4, 0, 1, 0) (4, 1, 0, 0) (5, 0, 0, 0)
But I'm having trouble coming up with a general formula, which I need for my application, where the numbers get too large to brute-force like this. Does anyone know how to compute the number of combinations for putting indistinguishable balls in urns, only with max capacity for each urn?
What do you mean by stars and bars with the principle of inclusion exclusion?
– MooseOfJoy Oct 19 '21 at 02:49