## How to count ways to distribute M items among n people?

In case 1, initially we got the expression without removing duplicate entries. In this case, we only need to divide as all people are considered to be unique in this case. In this case we need to multiply the expression obtained in case 1 by both and . The proofs for both of the multiplications are defined in case 2 and case 3.

**Are there n + 1 ways to decide how many a gets?**

You might think there are n + 1 ways to decide how many A gets, and then n + 1 ways to decide how many B gets, with C getting the rest. That argument would give a count of ( n + 1) 2. But that count would be incorrect. If you have 3 people, and 8 jelly beans, and have given 6 to A, you can’t then give 5 to B.

**How are n identical objects distributed among R groups?**

The post quotes the standard expression for the number of ways of distributing n identical objects among r groups. The wording used seems to indicate that you are aware of the counting argument that leads to this expression. In case I am wrong about that, please look at the Wikipedia Stars and Bars article.

### Are there any ways to distribute objects among groups?

I know that standard way of doing this is to solve the problem of distributing n identical objects and ( r − 1) partitions among themselves which can be done in C ( n + r − 1, r − 1) ways. But I am unable to prove to myself why it is not ( r + 1) n. Because each of the n objects has r+1 choices, either group1, group2,… group r or none at all.

**How to calculate the number of unique pairs?**

Let the number of unique elements be x. Then, the number of unique pairs would be x2. This is because each unique element can form a pair with every other unique element including itself. Below is the implementation of the above approach: Attention reader!

In case 1, initially we got the expression without removing duplicate entries. In this case, we only need to divide as all people are considered to be unique in this case. In this case we need to multiply the expression obtained in case 1 by both and . The proofs for both of the multiplications are defined in case 2 and case 3.

**How to count the number of ways to distribute mangoes?**

In this case, to calculate the number of ways to distribute m identical mangoes amongst n unique people, we just need to multiply the last expression we calculated in Case 1 by . This Proof is pretty much similar to the proof of last case expression. In case 1, initially we got the expression without removing duplicate entries.

## How to solve the friends pairing problem with dynamic programming?

We get (n – 1) * f (n – 2) Therefore we can recursively write f (n) as: f (n) = f (n – 1) + (n – 1) * f (n – 2) Since the above recursive formula has overlapping subproblems, we can solve it using Dynamic Programming. Since the above formula is similar to fibonacci number, we can optimize the space with an iterative solution.