I want to buy a $k$-combination of doughnuts, where $k$ is any amount less than or equal to the total doughnuts available. At the bakery there are $n$ different types of doughnuts but there are restricted amount left for each type of doughnut.
For example, In this case, the total doughnuts available is
4 + 2 + 3 + 2 + 7 + 2 + 8 = 28
and n = 7
Doughnut type Amount left
1 4
2 2
3 3
4 2
5 7
6 2
7 8
=====
28
Let's assume I want to buy a combination of $10$ doughnuts but I cannot have more than, for example $7$ of type $5$ doughnut and I can't have more than $3$ of type $3$ doughnuts. How many combination of $10$ doughnuts can I have altogether?
Let $a_i$ be the number of donuts you buy of type $i$. Then you have $$a_1+a_2+\cdots+a_7=10$$ subject to the constraints, $$0\le a_1\le4,0\le a_2\le2,\dots,0\le a_7\le 8$$ If you think about how you would multiply out the following product, you'll see you want the coefficient of $x^{10}$ in $$P(x)=(1+x+x^2+x^3+x^4)(1+x+x^2)\cdots(1+x+x^2+\cdots+x^8)$$ Now all those brackets contain geometric series, so you can rewrite as $$P(x)=(1-x^5)(1-x^3)\cdots(1-x^9)(1-x)^{-7}$$ and you can use the binomial theorem to get $$(1-x)^{-7}=1+{7\choose6}x+{8\choose6}x^2+{9\choose6}x^3+\cdots$$ So all you have to do is pick out the coefficient of $x^{10}$ in $$(1-x^5)(1-x^3)(1-x^4)(1-x^3)(1-x^8)(1-x^3)(1-x^9)\left(1+{7\choose6}x+{8\choose6}x^2+\cdots\right)$$ Now if you multiply out the first 7 terms, you get $$1-3x^3-x^4-x^5+3x^6+3x^7+2x^8-x^9-3x^{10}+{\rm\ higher\ terms}$$ (although you should check my work on that one), where we can ignore the higher terms because they can't contribute to the coefficient of $x^{10}$ that we are looking for. So, finally, you just have to pick out the coefficient of $x^{10}$ in $$(1-3x^3-x^4-x^5+3x^6+3x^7+2x^8-x^9-3x^{10})\left(1+{7\choose6}x+{8\choose6}x^2+\cdots\right)$$