Some time back, you helped a group of friends who were doing simulations for a computation-intensive investment company, and they've come back to you with a new problem. They're looking at n consecutive days of a given stock, at some point in the past. The days are numbered i = 1, 2, … , n; for each day i, they have a price p(i) per share for the stock on that day.
For certain (possibly large) values of k, they want to study what they call k-shot strategies.Ak-shot strategy is a collection of m pairs of days (b1, s1),(bm, sm), where 0 ≤ m ≤ k and
![]()
We view these as a set of up to k nonoverlapping intervals, during each of which the investors buy 1,000 shares of the stock (on day bi) and then sell it (on day si). The return of a given k-shot strategy is simply the profit obtained from the m buy-sell transactions, namely,
![]()
The investors want to assess the value of k-shot strategies by running simulations on their n-day trace of the stock price. Your goal is to design an efficient algorithm that determines, given the sequence of prices, the k-shot strategy with the maximum possible return. Since k maybe relatively large in these simulations, your running time should be polynomial in both n and k; it should not contain k in the exponent.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.