Suppose you are given a list L
of n
numbers and an integer k
Let F(X,k,n) be the k-product sum of first n elements of array X.
F(X,k,n) = F(X,k,n-1)+F(X,k-1,n-1)*X[n]
which you can solve using dynamic programming. Complexity = O(kn).
End conditions for F(X,k,n): When n=k F(X,k,k) = X[1]* X[2]*...*X[n]
More details:
F(X,1,1) = X[1]
F(X,1,i) = F(X,1,i-1)+X[i] for i=2...n
For j=2..n:
For i = 1..k:
if i