Number of ways to fill a bag using red, blue and white balls

116 Views Asked by At

There are $x$ balls of color red, $y$ balls of color blue and $z$ balls of color white. The white balls can be individually painted to any color (either red or blue). And there is a bag, which can be filled with red and blue balls. In how many ways can the bag be filled in such a way that the number of red balls in the bag is same as the number of blue balls?

(Note that it is not necessary to use all the balls.)

I have tried the above problem, and I can get the solution by summation of possibilities of number of red/blue balls in the bag (like compute for case 1- 1R and 1B ball, case2- 2R and 2B balls, and so on and add them up). It would be really helpful if this equation can be simplified to a single formula (or maybe a recurrence relation that can be simplified?) without requiring any summation, so that the value can be calculated in constant time.

PS: I'm sorry I really couldn't find a better title.

2

There are 2 best solutions below

0
On

If $x\ge y$, you must paint $k$ of the white balls red and $k+d$ of them blue, with $d:+x-y$, for some $k$ satisfying $0\le k\le\lfloor\frac{z-d}{2}\rfloor$. The number of solutions with indistinguishable white balls is then $\sum_{k=0}^{\lfloor\frac{z-d}{2}\rfloor}\binom{z}{k}\binom{z-k}{k+d}$. This formula generalises provided we define $d:=|x-y|$.

0
On

I consider the painted balls as indistinguishable. Denote by $2M$ the maximal realizable number of balls in the bag. The number of different ways to legally fill the bag then is $M+1$.

For the computation of $M$ assume $x\leq y$ with $y-x=:d$. Then we try to paint $d$ white balls red, and if white balls remain we paint them red and blue in equal numbers. This leads to $$M=\left\{\eqalign{&x+z\qquad\ \quad\qquad(z\leq d) \cr &y+\left\lfloor{z-d\over2}\right\rfloor\qquad(z\geq d)\ .\cr}\right.$$