Possible permutations of elements within sets I'm trying to resolve a permutation problem.
Say I have n apples, k bags and each bag has a c storage space. (Let's assume every bag has the same c storage), I need to know how many permutations are possible so that each apple is in a bag.
If each bag had $c = 1$, $\frac{k!}{(k-n)!}$ would solve my problem.
But c can vary and we don't care about the order within a bag. So if


*

*n = 3

*k = 2

*c = 3


(For this example, () are used to show a bag's size and [] the whole problem's context)
$[(1,0,0)(1,1,0)]$ is the same as $[(0,1,0)(0,1,1)]$ since the bags have the same number of apples in them in both the examples.
But
$[(1,1,0)(1,0,0))$ is the different from $((0,1,0)(0,1,1))$  because :


*

*In example 1 : $|bag1|=2$ and $|bag2|=1$ 

*In example 2 : $|bag1|=1$ and $|bag2|=2$.


I'm thinking I might need to divide something or apply another combination somewhere, but I can't figure what to do next. Any hint would be appreciated!
 A: Just to clarify, you want to find the number of ways to distribute $n$ indistinguishable apples into $k$ distinguishable bags, each bag holding at most $c$ apples. If that's so, here's a generating function solution.
First, suppose there is just a single bag. Then there's just one way to put the apples in the bag if $n\le c$ and no ways to do it if $n>c$. So, let $$f(x)=1+1x+1x^2+\cdots+1x^c+0x^{c+1}+0x^{c+2}+\cdots.$$ This function is called the generating function for the sequence of $c+1$ ones, followed by infinitely many zeros. The coefficient of $x^n$ of the function $f(x)$ coincides with the number of ways to put the apples in the bag. This function has a special property: it is a finite geometric series, so $f_c(x)=\frac{1-x^{c+1}}{1-x}$.
Now, suppose there are two bags. Then, for any number of apples you put in the first bag, you can put   the rest in the second bag, as long as neither bag overflows. This process exactly corresponds to the process of polynomial multiplication in the sense that the number of ways to put $n$ apples into two bags is the coefficient of $x^n$ in the function $\bigl(f_c(x)\bigr)^2=\bigl(\frac{1-x^{c+1}}{1-x}\bigr)^2$. 
This idea generalizes directly to the case of $k$ bags: the number of ways to distribute $n$ apples into $k$ bags (each with capacity $c$) is the coefficient of $x^n$ of $\bigl(f_c(x)\bigr)^k=\bigl(\frac{1-x^{c+1}}{1-x}\bigr)^k$.
Now, as is often the case with generating functions, it takes a little work to extract the necessary coefficient. In this case, it's not too bad. By the binomial theorem, $$(1-x^{c+1})^k=\sum_{j=0}^k\binom kj(-1)^jx^{j(c+1)}.$$ A similar identity gives that $$\frac1{(1-x)^k}=\sum_{j=0}^\infty\binom{j+k-1}jx^j.$$ Then, thinking of $(f_c(x))^k$ as the product of the previous two functions, the coefficient of $x^n$ in  $\bigl(\frac{1-x^{c+1}}{1-x}\bigr)^k$ is the sum $$\sum_{j=0}^{\min(k,\lceil\frac n{c+1}\rceil)}\binom kj(-1)^j\binom{n-j(c+1)+k-1}{n-j(c+1)},$$
which is the number of ways to distribute $n$ apples into $k$ bags with capacity $c$.
