Condition: it has an optimal sub-structure, and the sub-solution set has duplicates.
Maximum child segment and
[Problem description]
A sequence composed of N integers (which may be negative): A [1], a [2], a [3],…, A [n], for example, a [I] + A [I + 1] +... + The maximum value of the sub-segment and of a [J. When the given integer is negative, the sub-segment is defined as 0. According to this definition, the optimal value is
Max {0, a [I] + A [I + 1] +... + A [J]}, 1 <= I <= j <= N
For example, when (A1, A2, A3, A4, A5, A6) = (-,-5,-2), the maximum subsegment is 20.
[Analysis]
Set array a [K], 1 <= k <= N, the maximum child segment and X are defined:
You may wish to set
Here, B [J] indicates the maximum value of the sum of child segments ending with element J. In this case,
According to the definition of B [J], B [J] = B [J-1] + A [J] B [J-1]> 0
A [J] B [J-1]> = 0
[1] deformation 1: calculate the maximum submatrix and
Pku1050
Http://www.cnblogs.com/blackcruiser/articles/1786888.html
Solution: convert two-dimensional problems into one-dimensional problems.
[2] deformation 2: finding the maximum M sub-segment and
**************************************** ********
You have not read usaco's answer:
The longest prefix