Grouping items into groups with max size If I have up to $n$ non distinct items to distribute among $b$ distinct buckets that can hold up to $c$ items each, how can I find how many different states there can be? The ordering of items doesn't matter, and obviously $cb >= n$.
For example, if $n=4$, $b=3$ and $c=2$ then the answer would be $23$, with the possible states being (calculated using brute force):

 A | B | C
---+---+---
 0 | 0 | 0
 0 | 0 | 1
 0 | 0 | 2
 0 | 1 | 0
 0 | 1 | 1
 0 | 1 | 2
 0 | 2 | 0
 0 | 2 | 1
 0 | 2 | 2
 1 | 0 | 0
 1 | 0 | 1
 1 | 0 | 2
 1 | 1 | 0
 1 | 1 | 1
 1 | 1 | 2
 1 | 2 | 0
 1 | 2 | 1
 2 | 0 | 0
 2 | 0 | 1
 2 | 0 | 2
 2 | 1 | 0
 2 | 1 | 1
 2 | 2 | 0

 A: This is a problem well-suited to generating functions.
In each bucket we have the choice to put any number from $0$ to $c$ items. Each of these represents one state. We denote this by:
$$1+x+\ldots+x^c = \frac{x^{c+1}-1}{x-1}$$
using the power of $x$ to keep track of the number of items placed.
Because the buckets are distinct, we may multiply to check our possible states:
$$\left(\frac{x^{c+1}-1}{x-1}\right) \cdots \left(\frac{x^{c+1}-1}{x-1}\right) = \left(\frac{x^{c+1}-1}{x-1}\right)^b$$
It is now clear that the solution to this problem will be the coefficient of $x^n$ in this expression. In short, we seek: $$[x^n]\left(\frac{x^{c+1}-1}{x-1}\right)^b$$
The $[x^n]$ operator is manifestly linear, so that applying the binomial theorem to the numerator, we obtain:
$$[x^n]\left(\frac{x^{c+1}-1}{x-1}\right)^b = \sum_{i=0}^b\binom bi (-1)^{b-i}\ [x^n]\left(\frac{x^{i(c+1)}}{(x-1)^b}\right)$$
Now to compute $[x^n]\left(\frac{x^k}{(x-1)^b}\right)$:
\begin{align}
[x^n]\left(\frac{x^k}{(x-1)^b}\right) &= [x^{n-k}]\left(\frac1{(x-1)^b}\right)\\
&= \frac1{(n-k)!}\left(\prod_{j=0}^{n-k-1}-b-j\right)\cdot(-1)^{-(b+n-k)}\\
&= (-1)^{-b}\frac{(n+b-k-1)!}{(b-1)!(n-k)!} = (-1)^{-b}\binom{n+b-k-1}{b-1}
\end{align}
where in passing to the second line, we used the identity $[x^n](f) = \frac1n[x^{n-1}](f')$ repeatedly, and $[x^0](f) = f(0)$ once. (NB. Note that in passing, we have derived the solution to the stars and bars problem, since that corresponds to finding $[x^n]((1-x)^{-b})$.)
This means that for our original problem, we end up with:
\begin{align}
[x^n]\left(\frac{x^{c+1}-1}{x-1}\right)^b &= \sum_{i=0}^b\binom bi (-1)^{b-i}\ (-1)^{-b}\binom{n+b-i(c+1)-1}{b-1}\\
&= \sum_{i=0}^b (-1)^i \binom bi\binom{n+b-i(c+1)-1}{b-1}
\end{align}
It is clear that we may restrict $i$ to be smaller than $\dfrac{n+b-1}{c+1}$ due to the second binomial coefficient, but other than that I see no easy way to achieve further simplification of this sum.
