Dynamic Planning Summary (1) Maximum child segments and

Source: Internet
Author: User

Print? 1. For the one-dimensional problem, the maximum sum of consecutive sub-segments in a sequence is solved.
Status: one-dimensional array dp [I]: The maximum sub-segment ending with I, not the maximum sub-segment and of the previous I item. The two are different.
Transfer: if dp [I]> 0
Dp [I + 1] = dp [I] + a [I]
Else
Dp [I + 1] = dp [I]
Ans = max (dp [k]; k = 1, 2,... n ),
The principle of scrolling array can be used to optimize the space. The space complexity is O (1 ).
If ans> 0 dp + = a [I]
Else dp = a [I]
Ans = max (dp)
<A href = "http://acm.hit.edu.cn/hoj/problem/view? Id = 1760 "target = _ blank> hoj 1760 The jackpot </A>
 
2. Two-dimensional.
The sum [I] [j] indicates the sum of column 1st> j in each row (column.
Enumerate all rectangles with the complexity of O (n ^ 3), enumerate one row and two columns.
For a rectangle, the rows are reduced to a vertex, and the column is transformed into a one-dimensional problem.
Hoj 2558 maxsum
 
 
3. 3D
It is similar to converting two-dimensional data into one-dimensional data.
First, the two-dimensional matrix and of the bottom surface (or other surface) are preprocessed.
Sum [I] [j] [k]: Elements of the matrix at layer I with the diagonal endpoint () and (j, k.
Then, we use the complexity of O (n ^ 5) to enumerate all cubes, compress the bottom surface into a vertex, and process the remaining one dimension as one dimension.
Hoj 2555

1. For the one-dimensional problem, the maximum sum of consecutive sub-segments in a sequence is solved.
Status: one-dimensional array dp [I]: The maximum sub-segment ending with I, not the maximum sub-segment and of the previous I item. The two are different.
Transfer: if dp [I]> 0
Dp [I + 1] = dp [I] + a [I]
Else
Dp [I + 1] = dp [I]
Ans = max (dp [k]; k = 1, 2,... n ),
The principle of scrolling array can be used to optimize the space. The space complexity is O (1 ).
If ans> 0 dp + = a [I]
Else dp = a [I]
Ans = max (dp)
House 1760 The jackpot

2. Two-dimensional.
The sum [I] [j] indicates the sum of column 1st> j in each row (column.
Enumerate all rectangles with the complexity of O (n ^ 3), enumerate one row and two columns.
For a rectangle, the rows are reduced to a vertex, and the column is transformed into a one-dimensional problem.
Hoj 2558 maxsum


3. 3D
It is similar to converting two-dimensional data into one-dimensional data.
First, the two-dimensional matrix and of the bottom surface (or other surface) are preprocessed.
Sum [I] [j] [k]: Elements of the matrix at layer I with the diagonal endpoint () and (j, k.
Then, we use the complexity of O (n ^ 5) to enumerate all cubes, compress the bottom surface into a vertex, and process the remaining one dimension as one dimension.
Hoj 2555


 

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.