Arranging numbers for a given sum

215 Views Asked by At

Suppose I have numbers the $\{0,1,2,3\}$ in how many ways can one arrange them so the sum would be equal to 5? For instance, $$ \begin{array}{cccc} 0 & 1 & 2 & 2 \\ 1 & 0 & 2 & 2 \\ 1 & 2 & 0 & 2\\ 1 & 2 & 2 & 0\\ 0& 2 & 2 & 1\\ \vdots & & & \\ 2 & 3 & 0 & 0 \\ \vdots \end{array} $$ As you can see I am looking for ALL (including permutations) possible combinations (such that the sum of each row is 5). I was wondering if this can be represented by binomial coefficients?

side note: This is just a simplified example, I would want to then generalise such that sum of each row would be (0 to 8), i.e. In how many ways one can arrange 0,1,2,3 so the sum would be 0 and 1 and ... 8. But I wanted to know how this works first for a given sum.

2

There are 2 best solutions below

0
On BEST ANSWER

Let us consider the Diophantine Equation $x_1+x_2+x_3+x_4 = 5$ with integer solutions. We place the restriction that for all $i$ we have $0\le x_i \le 3$. This is a well-known problem. First, we consider the case with no upper bound, then we subtract the cases where an upper bound is violated.

We consider the case when $0\le x_i$ (with no upper bound). There are $\dbinom{5+4-1}{5} = \dbinom{8}{5}$ ways to generate this sum. Now, we use Inclusion/Exclusion to subtract off sums that violate the upper bound of 3. It is not possible for two of the summands to be at least 4 (since we have the lower bound of zero already). So, only one upper bound can be violated at a time, but any one of the four will be violated. So, we assume $x_1\ge 4$ while $0\le x_2,x_3,x_4$. Solutions with these lower bounds are in one-to-one correspondence with solutions to the Diophantine equation with $y_1=x_1-4$, $y_2=x_2, y_3=x_3,y_4=x_4$ and $0\le y_i$. Now, we have $5=x_1+x_2+x_3+x_4 = y_1+4+y_2+y_3+y_4$ so $y_1+y_2+y_3+y_4 = 1$. This has $\dbinom{1+4-1}{1} = \dbinom{4}{1}$ solutions. Since any of the upper bounds could be violated in this way, we have the total number of solutions (with both upper and lower bounds) as:

$$\dbinom{8}{5}-4\dbinom{4}{1} = 40$$

2
On

If you have n distinct objects and you want to make all possible arrangements out of them, then there are n! ways to do so.
But, say if r1 out of n objects are of one kind, r2 of other kind, and so on till rk of other kind, then, total possible arrangements of n objects would be:
$$ \frac{n!}{r1!r2!....rk!} $$

For getting sum 5 using only 4 summands(repetitions allowed), you have following choices:
3200, 3110, 2210 and 2111.

For 3200 case: 0 is repeated twice. So, total arrangements are $ \frac{4!}{2!} $ =12 ways
For 3110 and 2210 case: proceed similarly. $ \frac{4!}{2!} $ =12 ways
For 2111 case: $ \frac{4!}{3!} $ =4 ways

So, total ways are 12+12+12+4=40.