Let OPT('i) denote the minimum Cost ofa solution for weeks l through ln an optimal
solution, we either use company A or company B for the im week. If we use company A,
we pay rs; and can behave optimally up through week 1- l. If we use Company B for week
2, then we PZMV 40 for this contract, and so there‘s no reason not to get the full benefit of it
hy starting it at week i - 3; thus we can behave optimally up through week '6 - 4, and then
invoke this contract.
Thus we have
OPTU) 1 l'I]ill(f51 + OPT(i-1),4?f+ OPT(i f
We can build up these OPT values in order of increasing i, spending constant time per
iteration, with the initialization OPT(i) 1 0 for I 0.
The desired value is OPT(n), and we can obtain the schedule by tracing back through
the array ef OPT values.