Summation on multiplication of two numbers that equal to a specified sum

69 Views Asked by At

Suppose I have N terms like $a_ix_i$ and coefficient $x$ is a constant for each $i$. How should I find all combinations of $a_i$ such that $\sum_{i=0}^Na_ix_i=S$? $a_i\in \{0,1,2,...,\}$ $x_i\in \{2,1,6,.,3\}$

How about a matrix like \begin{bmatrix} a_{11}x_{11} & b_{12}x_{12} & x_{13} & \dots & c_{1,n}x_{1n} \\ a_{21}x_{21} & b_{22}x_{22} & x_{23} & \dots & c_{2,n}x_{2n} \\ \\ a_{d1}x_{d1} & b_{d2}x_{d2} & x_{d3} & \dots c_{d,n}& x_{dn} \end{bmatrix} that I have to select one term from each columns to sums to $S$? Any specific algorithm or optimization model for these problems? Any hint what should I looking for? Thanks

Edit: To anyone who faces the same problem. Comments in this question helped me achieve what I wanted.