Let there be $n$ distinguishable balls and $m$ distinguishable bins, each bin of size $s$, that is, we cannot place more than $s$ balls into it. How many possibilities are there to place the balls into the bins?
-
Here is an equivalent question with a nice answer: http://math.stackexchange.com/questions/665178/how-many-ways-to-distribute-k-indistinguishable-balls-over-m-of-n-distingu?lq=1 – Rus May Oct 16 '14 at 14:58
2 Answers
This can be done using species and generating functions. If some bins are allowed to remain empty the species is
$$\mathfrak{S}_{=m}(\mathfrak{P}_{\le s}(\mathcal{Z})).$$
This gives the generating function $$P(z) = \left(\sum_{k=0}^s \frac{z^k}{k!}\right)^m$$
and the closed formula $$p_{n,m,s} = n! [z^n] \left(\sum_{k=0}^s \frac{z^k}{k!}\right)^m.$$
If no bins are allowed to remain empty the species is
$$\mathfrak{S}_{=m}(\mathfrak{P}_{1\le\cdot\le s}(\mathcal{Z})).$$
This gives the generating function $$Q(z) = \left(\sum_{k=1}^s \frac{z^k}{k!}\right)^m$$
and the closed formula $$q_{n,m,s} = n! [z^n] \left(\sum_{k=1}^s \frac{z^k}{k!}\right)^m.$$
The following Maple code implements a brute force calculation to verify these values and the generating functions as well.
P := proc(n, m, s) n!*coeftayl(add(z^k/k!, k=0..s)^m, z=0, n); end;
Q := proc(n, m, s) n!*coeftayl(add(z^k/k!, k=1..s)^m, z=0, n); end;
P_ex :=
proc(n, m, s)
option remember;
local ind, d, ms, k, res, pos;
res := 0;
if m = 1 then
if n <= s then res := res + 1 fi;
return res;
fi;
for ind from m^(n+1) to m^(n+1)+m^n-1 do
d := convert(ind, base, m);
ms := convert([seq(d[k], k=1..n)], multiset);
for pos to nops(ms) do
if ms[pos][2] > s then
break;
fi;
od;
if pos = nops(ms)+1 then
res := res + 1;
fi;
od;
res;
end;
Q_ex :=
proc(n, m, s)
option remember;
local ind, d, ms, k, res, pos;
res := 0;
if m = 1 then
if n <= s then res := res + 1 fi;
return res;
fi;
for ind from m^(n+1) to m^(n+1)+m^n-1 do
d := convert(ind, base, m);
ms := convert([seq(d[k], k=1..n)], multiset);
for pos to nops(ms) do
if ms[pos][2] > s then
break;
fi;
od;
if pos = nops(ms)+1 and nops(ms) = m then
res := res + 1;
fi;
od;
res;
end;
I was not able to find OEIS entries for these.
- 64,728
-
Thank you. Can you explain, how I might apply the closed formula, i.e. what the parameter z stands for, exactly? I'm sorry if this is a really stupid question. – ComibinatorialCrocodile Oct 15 '14 at 21:14
-
The above might not be suitable for a first combinatorics course. Maybe someone from the set of experts on MSE will post an elementary derivation. If you want to understand the meaning of the parameter $z$ and the concept of generating functions there is this Wikipedia article on Symbolic / Analytic Combinatorics. – Marko Riedel Oct 15 '14 at 21:21
-
It would be very helpful if you could post the coefficient that I need to compute this quantity. – ComibinatorialCrocodile Oct 15 '14 at 21:34
-
The two functions at the top of the Maple code namely P and Q will instantly produce the answer for any $n,m$ and $s$. Consult these to see how to input the formula into a CAS. Any one of the major CAS can do this and MSE is likely to have contributors that use them. – Marko Riedel Oct 15 '14 at 22:54
Include-Exclude with the sets $A_j = \{ \text{ box j has more than s balls } \}, \,\, j=1,2,\dots,m$. The number of ways is
$$ w := \left| \left(\bigcup_{j=1}^m A_j \right)^C \right| = \sum_{r=0}^m (-1)^r \binom{m}{r} |\{\text{ boxes 1,2,...,r have more than s balls }\}| $$
because for an intersection of size $r$ it doesn't matter which particular $j$'s are in it. To calculate the ways where boxes $1,2,\dots, r$ have more than $s$ balls (i.e. at least $s+1$ balls), we break it into cases of how many balls in total go to the boxes $1,2\dots, r$ (call that $u$) and use the associated Stirling numbers of the second kind ${a \brace b}_{\geq c} = $ number of ways to partition a set of size $a$ into $b$ parts where each part has at least $c$ elements. Notice that this doesn't account for the order of the parts (i.e. bins) so we must multiply by the way they can be ordered. Luckily, since the balls are distinguishable, every part is different and this is just $r!$ when there are $r$ parts.
So the answer is
$$ w = \sum_{r=0}^m (-1)^r \binom{m}{r} \sum_{u=r(s+1)}^n \binom{n}{u} r! {u \brace r}_{\geq s+1} (m-r)^{n-u} $$
- 12,367