Finding the number of solutions satisfying an equation?

65 Views Asked by At

Given one condition $x_1+x_2+x_3=n$ where n is known number. Given a set of data X={$a_1,a_2....a_n$}. Can you help me find all possible cases satisfying the above condition $x_1+x_2+x_3=n$ ???

2

There are 2 best solutions below

0
On BEST ANSWER

There is a standard technique for solving this problem. It is to note that the problem is similar to partitioning n 1's into 3 sets. So, for example, if n = 8, we would think of:

1 1 1 | 1 1 1 1 | 1 where the '|' are the dividers that partition the 1's into 3 sets. In this case, it would mean $x_1=3, x_2=4$ and $x_3=1$.

Generalizing from this example, it means the number of solutions = number of permutations of n 1's and 2 '|' = $\binom{n + 3 - 1}{3 - 1}= \binom{n+2}{2}$

0
On

For each $a_n, a_m$, check if the set contains the value $n - a_n - a_m$