Number of groups containing at least 1 and at most k elements In Counting of the elements in a set, I've been answered that the number of ways of grouping $n$ elements
in $n_{G}$ groups such that each group contains at least 1 element is 
$$
{n-1 \choose n_{G}-1} \qquad (1)
$$
Now, I'm wondering how many ways are there to combine $n$ elements into $n_{G}$ groups such that each group contains at least 1 element and at most $k$ elements?
Denoting $\#\left(n,n_{G},j,k\right)$ the number of ways of grouping $n$ points into $n_{G}$ groups where each group contains at least $j$ and at most $k$ elements, (1) can be written $\#\left(n,n_{G},1,\infty\right)$ and my question aims at determining
$\#\left(n,n_{G},1,k\right)$.
I think this could be evaluated as $\#\left(n,n_{G},1,k\right)=\#\left(n,n_{G},1,\infty\right)-\#\left(n,n_{G},k+1,\infty\right)$ but I'm not able to compute $\#\left(n,n_{G},k+1,\infty\right)$ either.
Another way would be to adapt the stars and bars argument to groups
larger than one, but I don't really see how.
Edit 1
It seems that these 2 questions are closely related:


*

*An efficient method for computing the number of submultisets of size n, of a given multiset

*Drawing Elements from Multiple Sets
Edit 2
After reading documents about generating function (especially this one, I figured out that the generating function for my problem is:
$$
g(x)=(\sum_{i=1}^{k} x^i)^{n_G}
=x^{n_G} \left(\frac{1-x^k}{1-x}\right)^{n_G}
$$
but I can't really go further. Any idea ?
 A: Note: I've changed your notation for simplicity, my $g$ is your $n_G$.
One way of interpreting the stars and bars argument for grouping $n$ elements into $g$ groups  with at least one element in each group is that it is the number of ways of placing $g$ dominos on a strip of $n+g$ squares with a domino covering the first square.  Removing the first domino and its squares, this is equivalent to the ways of placing $g-1$ dominos on a strip of $n+g-2$ squares.  Replacing each domino by a bar, and each empty square with a star, we see that this is the way of placing $g-1$ bars and $n-g$ stars, or $\binom{n-1}{g-1}$.
But you knew all that.  Fortunately, only a slight modification of the reasoning coupled with inclusion-exclusion is needed to count the number of ways of partitioning into $g$ groups with at least one and most $k$ elements in each group.
What we want to do is remove from the count of all ways of partitioning into groups having at least 1 element those having at least one group with more than $k$ elements.  We can count these by counting the number of ways of placing $g-1$ dominos and one $k+2$-omino ($k+2$ squares: $1$ for a bar and $k+1$ elements, so there are more than $k$ elements in one group).
There are $g\binom{n-k-1}{g-1}$ such partitions, where

*

*$g$ is the number of ways we can arrange the $k+2$-omino and dominos ignoring the unoccupied cells, and

*$\binom{n-k-1}{g-1}$ is the number of ways of arranging the extra cells.

Unfortunately we have overcounted the partitions that contain more than one group with more than $k$ elements.  So we use inclusion exclusion to get
$$ \sum_{i=0}(-1)^i\binom{g}{i}\binom{n-ik-1}{g-1}$$
Here:

*

*$\binom{g}1$ is the number of ways of arranging $i$ $k+2$-ominos and $g-i$ dominos

*$\binom{n-ik-1}{g-1}$ is the number of ways of grouping the other squares.

The sum ends when one of the two binomials is zero, i.e. when $i>g$ or $g>n-ik$.
A: It's not 100% clear what you're trying to count; but given that you liked the stars and bars argument for the other question, I assume that if the elements are $\{1,2,3,4,5,6\}$ so $n=6$, and that $n_G=3$ and $k=3$ that you want to the answer to be 7: (1,2,3), (1,3,2), (2,1,3), (2,3,1), (3,1,2), (3,2,1), and (2,2,2) are the only permitted results to be counted. (Some might want to count partitions, where in this case there would only be 2 representatives: (3,2,1) and (2,2,2); for these enquirers, I would recommend googling Ferrer's diagram.).
Now maybe there's a nice simple closed form for this (perhaps using Stirling numbers, they always seem to pop up), but I'll have to go the recurrence route...
If we define $f(n,n_G,k)$ as the number of groupings you request, then my basic approach is along the lines of thinking of the satisfying groupings as the disjoint union of:


*

*Results where no group has more than $k-1$ elements; i.e. those counted by $f(n,n_G,k-1)$.

*Results where exactly 1 group has $k$ elements, and none of the remaining $n_G-1$ groups has more than $k-1$ elements; i.e. ${n_G \choose 1} f(n-k, n_G-1, k-1)$.

*Results where exactly 2 groups have $k$ elements, and none of the remaining $n_G-2$ groups has more than $k-1$ elements; i.e. ${n_G \choose 2} f(n-2k, n_G-2, k-1)$.

*Etc. until we have $j$ groups having exactly $k$ elements and none of the other remaining $n_G - j$ groups has more than $k-1$ elements, where $j$ is the largest integer with $n<(j+1)k$. The last constraint is the same as saying that $j = \lfloor \frac{n}{k} \rfloor$. This would provide ${n_G \choose j} f(n-jk, n_g-j, k-1)$ elements. 


Using this way of thinking we get the recurrence (with a few edge cases taken care of first):
$k \cdot n_G < n$ or $n<n_G \rightarrow f(n,n_G,k) = 0$
$n = n_G \rightarrow f(n,n_G,k) = 1$
$k \gt n - n_G \rightarrow f(n, n_G,k) = {n-1\choose n_G-1}$
Otherwise, $f(n,n_G,k) = \sum\limits_{i=0}^{\lfloor \frac{n}{k} \rfloor} {n_G \choose i}f(n -ik, n_G-i, k-1)$
A: Reading the Wikipedia article about compositions, I found this article which gives another version of the result (Example 2.7 p.3), i.e.:
$$
\#(n,n_G,1,k) = F(k,n+k-1)
$$
where F(a,b) is the shifted a-generalized Fibonacci number.
