# Number of ways to choose balls

The context of the problem is different but I'll try to describe using red and black balls.

Let say we have 5 boxes with red and black balls and we take one from each box. The number of ways to get only red balls is $r_1 \cdot r_2 \cdot r_3 \cdot r_4 \cdot r_5$ where r is the number of red balls in the each box. If we want to get exactly 3 red and 2 black balls the number of ways is the sum of 10 products $(r_1 \cdot r_2 \cdot r_3 \cdot b_4 \cdot b_5 ) + ( r_1 \cdot r_2 \cdot b_3 \cdot r_4 \cdot b_5 ) + \cdot \cdot \cdot + ( b_1 \cdot b_2 \cdot r_3 \cdot r_4 \cdot r_5)$.

Now I have a slightly different problem. Each box has red, black and some other balls that we don't know yet the color (red or black). The number of balls with unknown colors is $q$.

If we take one ball from each box and we want all to be red, the maximum number of possible ways now is $(r_1+q_1)(r_2+q_2)(r_3+q_3)$...since each unknown color can be red.

My question is what is the maximum number of ways to get 3 red and 2 black balls in the second version?

So, from all combinations of balls $N = (r_1+b_1+q_1)(r_2+b_2+q_2)\cdots(r_5+b_5+q_5)$, how many of them are candidates to have 3 red and 2 black balls?

• Suggestion: You can write this as a maximization problem. Since $q_1,q_2,q_3,q_4,q_5$ are your parameters, can you explicitly write the function $f(q_1,q_2,q_3,q_4,q_5)$ that you want to maximize? – iamvegan Aug 21 '16 at 21:35
• I want the maximum number of valid combinations, not to find the actual unknown colors. I.e permutation rrrbq is valid because can have 3 red and 2 black. permutation qqbbb is not valid because has 3 black.... I dont want to test each combination. b1,b2,b3... are parameters also – albert Aug 21 '16 at 22:03
• Sorry I misled you. Define $x_i,y_i$ as number of unknown red and blue balls, respectively in the $i$th box where $x_i + y_i = q_i$. Then define the 5-tuples $\mathbf{x}=(x_1,x_2,x_3,x_4,x_5)$ and $\mathbf{y}$ similarly. You need to write a function $f(\mathbf{x},\mathbf{y})$ in terms of $r_i,b_i,q_i,x_i,y_i$. This will make your problem very clear. The way you describe your problem is very ambiguous. – iamvegan Aug 21 '16 at 22:38
• Can you please rewrite your problem in a better format? Also please use TeX when you describe a mathematical variable or identity. – iamvegan Aug 21 '16 at 22:41

This answer is based mainly on a reading of the last sentence of the question, which seems to imply that for each of the $N$ possible combinations of balls, if there is a color assignment to the unknown balls that makes three red and two blue, we count that combination.
If the actual question is how to color the "unknown" balls so that the chance of three red and two blue is maximized (that is, to put $r'_i$ red and $b'_i$ blue balls in box $i$ such that $r'_i\geq r_i$, $b'_i\geq b_i$, and $r'_i + b'_i = r_i + b_i + q_i$ so as to maximize the number of combinations of three red and two blue), the following won't be of much use.
As a way of reducing this to a more familiar problem, let $R$ be the number of already known red balls among the five you select, $B$ be the number of already known blue balls among the five you select, and $Q$ the number of "unknown color" balls among the five you select.
For any particular value assignment to $R$, $B$, and $Q$, for example, $R=1$, $B=1$, $Q=3$, you can determine how many ways there are to select balls in that way.