Combination problem distributing In how many ways 8 candies can be distributed be among 3 children?


I have done by using combination method $8C4$ but the answer is given 45. 
someone has done in this way: 


  



008 in 3 ways 
710 in 6 ways
611 in 3 ways
620 in 6 ways
530  in 6 ways
521 in 6 ways
440 in 3ways
431 in 6 ways
422 in 3   ways
332 in 3 ways

in total 45 ways.

Why my formulation is not right.  And how can I do this math within the formula I have writen? I mean within short time done.
Original Answer

Seeing as you asked me to look at this problem for you I'll give my own answer. I get that your main concern here is understanding and not just being given the correct solution. But, correctness has a context. Your formulation, although lengthy has none the less given the correct answer.

If you don't understand how to prove the stars and bars formula, instead I'll show you a method using the basic idea of the stars and bars diagram to hopefully understand what is going on. From this you may go on to understand the proof.

The two bars stand between the three children. Start with the two children on the left with no sweets and the child on the right with all of them. Leave the left most bar at the left and move the right hand bar, past one star at a time, to the right. (This first one is equivalent to (0, 0, 8))

$$\ |\ |\ \bigstar\bigstar\bigstar\bigstar\bigstar\bigstar\bigstar\bigstar$$

The following is what it looks like after two steps to the right (which is equivalent to (0, 2, 6))

$$\ |\ \bigstar\bigstar\ |\ \bigstar\bigstar\bigstar\bigstar\bigstar\bigstar$$

You can do this 8 times. So the first step has 9 combinations.

Then put the two bars after the first star and again leave the left hand bar where it is and move the right hand bar, one at a time to the right. (This one is equivalent to (1, 0, 7))

$$\ \bigstar |\ |\ \bigstar\bigstar\bigstar\bigstar\bigstar\bigstar\bigstar$$

You can do this 7 times. So the second step has 8 combinations.

You should be seeing a pattern by now.

Each step decreases by one. The last step has the two bars on the far right with the right hand bar having nowhere else to go, finishing with 1 combination. Thus the pattern gives you a triangular number.

Total = 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 = 45

Addendum 1: Stars And Bars Proof

Stars and Bars Theorem $n\leq k$: We have $n$ containers and $k$ identical items to distribute. If you start by insisting that each container has at least 1 item in it, you may as well start by putting 1 item into each container. You have no choice with this. Hopefully you can see that, counting wise, this is the same as starting with $k-n$ items and allowing empty containers.

So, lets start with $k$ items, $n$ containers and insist at least one in each container. In the following argument this allows having gaps only between stars. If we tried to start with having empty containers, you have a problem with bars accumulating at the edges and the argument doesn't work.

Consider the following diagram with $k=11$ and $n=4$. The 3 bars represent the boundaries between separate containers, where $3=4-1$. We can't put bars at the left and right hand edges, otherwise that would mean we had a container at the right or left or both ends with no items in so the outside edges are automatically boundaries of the first and last containers.

\begin{align*}
|\ \bigstar\bigstar\bigstar\bigstar\bigstar\bigstar\ |\ \bigstar\bigstar\ |\ \bigstar\bigstar\bigstar &amp;= (0, 6, 2, 3) \text{ this is not allowed } \\
\bigstar\ |\ \bigstar\bigstar\bigstar\bigstar\bigstar\ |\ \bigstar\bigstar\ |\ \bigstar\bigstar\bigstar &amp;= (1, 5, 2, 3) \text{ this is allowed }
\end{align*}

Think of this as allocating the gaps between stars to the bars and note also that you can't have more than one bar in a single gap, otherwise we wouldn't be able to apply the standard combinations formula. So, we have in general $k$ stars, $k-1$ gaps between them to choose from and $n-1$ bars to distribute in them, which gives ${{k-1}\choose{n-1}}$ ways.

As above, insisting on at least 1 in each container, is the same as having $k-n$ items and allowing 0 in any container. So, if we distribute $k+n$ items into $n$ containers with at least 1 in each container, this is the same, counting wise, as distributing $k$ items into $n$ containers allowing 0 in any container.

Thus we have $${{k+n-1}\choose{n-1}} = \frac{(k+n-1)!}{((k+n-1)-(n-1))!(n-1)!} = \frac{(k+n-1)!}{k!(n-1)!} = {{k+n-1}\choose{k}}.$$
There is a formula for working this out called the related to the binomial coefficient it is: n!/(n-k)!k!, where n is the number of sweets and k is the number of children

Using the formula there are 112 possible combinations of sweets and children