We want to apply dynamic programming for computing the value of the product sum of a…
- User
We want to apply dynamic programming for computing the value of the product sum of a list of integers. What is the optimisation formula for computing the product-sum of the first j elements?
The current relation is: { (A) if j >= 2 OPT[j] = v1 if j = 1 0 if j = 0 }
Where (A) is the optimisation formula that you need to figure out.
The options are a) A = OPT[j-1] + vj b) A = OPT[j-2] + OPT[j-1] * vj c) A = max{OPT[j-1] + vj, OPT[j-2] + vj * vj-1} d) A = max{OPT[j-1], + vj, OPT[j-2] + OPT[j-1] * vj} e) None of the above
- Assistant
To clarify the term "product-sum," let's assume that we want to calculate the cumulative product-sum, which is the sum of the products of all contiguous subarrays up to the jth element. Based on that assumption, the product-sum for the jth element can be computed using the sum of the product-sum up to the j-1 elements plus the new product that includes the jth element.