CSCC73H3 Lecture Notes - Substring, Glossary Of Ancient Roman Religion, Dynamic Programming
Document Summary
M [i] = maximum number that is the sum of a contiguous subsequence of s that ends in position i. We claim that the following is a recursive formula to compute m [i] for all i [1n]. M [i] =(s[1], max(s[i], s[i] + m [i 1]), if i = 1 if i > 1. For i > 1, let xi be the contiguous subsequence of s that ends in position i and has the maximum possible sum among all such subsequences. Thus, xi = ys[i], where y is the (possibly empty) pre x of xi up to and excluding the last element, s[i]. Then xi = s[i] and obviously m [i] = s[i]. y is nonempty. Therefore, y is a contiguous subsequence of s that ends in position i 1 (otherwise. Case 2. xi would not be a contiguous subsequence of s that ends in position i). So, y = xi 1 and therefore xi = xi 1s[i].