Dynamic Planning (△)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.