Given a list N . I need to sum up products of all ${N}\choose{k}$ sublists.
It doesn't matter if two elements are same.
example N = 3
[1, 2, 2]
k = 2
[1, 2], [2, 2], [2, 1]
ans = 1*2 + 2*2 + 2*1 = 8
This was given at a math programming contest. the solution was to represent each number as 1 degree polynomial $(x+value)$ and multiply all the polynomials and the coefficient of $$(x^{N-k})$$ was the answer. But I am not able to understand how.
Hint: This is very closely tied to the binomial theorem: $(x+y)^n = {{n}\choose{k}}x^{n-k}y^k$, except here the $y$ is not constant. Instead, let $y_1,y_2,...,y_n$ be the elements of the list (not necessarily distinct, as you specified) and we are curious about the coefficient of $x^{n-k}$ in the expansion of $(x+y_1)(x+y_2)...(x+y_n)$. We find the coefficient of $x^{n-k}$ is
$$y_1 \cdot y_2 ... y_{k-1} \cdot y_k +$$ $$y_1 \cdot y_2...y_{k-1} \cdot y_{k+1} +$$ $$... +$$ $$y_{n-k+1} \cdot y_{n-k+2} ... y_{n-1} \cdot y_n$$
Each of those terms in the summation is the product of one of the combinations in ${{n}\choose{k}}$ (because the term in the polynomial is $x^{n-k}$, that means that $k$ of the $y_i$ terms were multiplied together).