I have been struggling through a dynamic programming exercise and I can't seem to get the hold of it. I'll write here the problem and also it's solution stating explicitly what I don't understand.
We are given 2 sequences u1,u2,...,un and d1,d2,...,dm and a matrix of dimensions n x m built of positive integers C=[cij]. A list of k pairs
((ui1, dj1),(ui2,dj2),...,(uik,djk)) is said to be non-intersecting if
i1 < 12 <..< ik and j1 < j2 <...< jk.
The "compatibility of a list" is said to be the compatibility of the sum of the pairs that it is made of, that is Ci1j1 + Ci2j2 + ... + Cikjk
Example :
Consider the matrix C = [Cij], so Cij = squared(i + j). Let i be
i = 1, 2, 3, j = 1, 2, 3, 4 and k = 2. Some lists of 2 non-intersecting pairs are these ((u1, d2),(u3, d3)) with a compatibility of 9 + 36 = 45,
((u2, d2),(u3, d4)), with compatibility 16 + 49 = 65, and ((u1, d1),(u2, d4)), with compatibility of 4 + 36 = 40. Some lists that are not non-intersecting are the following : ((u2, d2),(u3, d1)),((u1, d4),(u3, d3)),((u3, d2),(u2, d3))
Solution:
M(i, j, t) = maximum cost of t non-intersecting pairs taken from ui,...,un and dj,...dm
Recurrence equation :
M(i, j, t) = max {M(i + 1, j + 1, t − 1) + c(i, j), M(i, j + 1, t),M(i + 1, j, t).}
M(i, j, 0) = 0M(i, j, t) = −∞, if t > min{n − i + 1, m − j + 1}M(i, j, t) = 0, if i > n or j > m
I don't under the reccurrence very well and why do we assign −∞ to M(i, j, t) when t > min{n − i + 1, m − j + 1} but 0 when i > n or j > m
The solution is M(1, 1, k).