All possible combinations of seven numbers that sum up to a specific value under constraints.

171 Views Asked by At

I know this (or similar questions) may have already been asked a ton of times, but I couldn't really find a good answer for my specific case, so here again. I would like to implement the following formula:

$G(0,1,\ldots,5) =0$

$G(N) = G(N-1) + \underbrace{\sum\limits_{a}\sum\limits_{b}\sum\limits_{c}\sum\limits_{d}\sum\limits_{e}\sum\limits_{f}\sum\limits_{g}}_{a+b+c+d+e+f+g=N-6} F(a)F(b)F(c)F(d)F(e)F(f)F(g)$

with $N\in \lbrace 6,7,\ldots,180\cdot 7 -1\rbrace$ and $a,b,\ldots,g\in\lbrace 0,1,\ldots,179\rbrace$,

in Python, whereby F is a float number between 0 and 1.

The problem is that everytime I get it done it doesn't really work due to the high number of loops and so on. My math related question now is: Is there a way to simplify this formula? (so that it somehow doesn't contain so many sums in one go, etc.)

Again if there is a solution somewhere I would also be glad to just be redirected to it. :D Thanks.

1

There are 1 best solutions below

2
On BEST ANSWER

Let $$T(n, k) = \sum\limits_{x_1 + \ldots + x_k = n} \prod\limits_{i=1}^k F(x_i)$$

Then your expression can be rewritten as $G(N) = G(N - 1) + T(N - 6, 7)$.

And $T(n, k)$ can be computed in $O(n^2k)$ operations using standard dynamic programming or recursion with memorization, as we have $$T(n, k + 1) = \sum\limits_{x_{k + 1} = 0}^{179} F(x_{k + 1}) \cdot T(n - x_{k + 1}, k)$$