Number of ways to give chocolates.

202 Views Asked by At

There are $N$ students and $M$ types of chocolates. How many ways are there to distribute the chocolates to the students given that, no more than two consecutive numbered students, gets the same type of chocolate.

I was able to figure out a case, when $N\geq M$, and that would be $$M^N - \begin{pmatrix}N\\2\end{pmatrix}\cdot\begin{pmatrix}N\\3\end{pmatrix}\cdots\begin{pmatrix}N\\N-1\end{pmatrix}$$

The number of chocolates are infinite. There's just $M$ types of chocolates.

2

There are 2 best solutions below

2
On

Hint. Divide the problem in two distinct parts.

1) How many ways are there to distribute the chocolates to the students given that, no two consecutive numbered students gets the same type of chocolate? $$\underbrace{(M)}_{\text{student $1$}}\cdot \underbrace{(M-1)}_{\text{student $2$}}\cdots \underbrace{(M-1)}_{\text{student $N$}}=M(M-1)^{N-1}.$$

2) How many ways are there to distribute the chocolates to the students given that, exactly two consecutive numbered students gets the same type of chocolate? We may select the couple of consecutive students in $N-1$ ways. Now consider such couple as a unique student and use 1). What formula do we get for this case?

The final answer is the sum of the numbers obtained in 1) and 2).

1
On

Let say there is no pairs of consecutive students with a same type of chocolate given. Total number of different distributions like this is $M(M-1)^{N-1}$ since first student may get any type of chocolate but each next student can't get same type as previous.

Then we can say there was exactly one pair of students. Total number of such distributions is $(N-1)M(M-1)^{N-2}$, where $N-1$ annotes number of possible pairs of consecutive students and power lowerize by one since one of the students has no choice than to pick same type as his preceder.

You can continue increasing number of pairs of consecutive students with a same type up to $\lfloor N/2\rfloor$. Let K be the number of such pairs in one of distributions. Number of ways to pick which of the pairs it would be is the same as putting rest of $N-2K$ students into $K+1$ boxes (spaces before, after and between consecutive pairs) which is $ N-K \choose K$

So in the end you just have to sum it all: $$\sum_{K=0}^{\lfloor N/2\rfloor}{N-K \choose K}M(M-1)^{N-K-1}$$