You are given an array a consisting of n integers. You should divide a into continuous non-empty subarrays (there are 2
n−1 ways to do that).
Let s=a
l+a
l+1+…+a
r . The value of a subarray a
l,a
l+1,…,a
r is:
-
(r−l+1) if s>0 ,
-
0 if s=0 ,
-
−(r−l+1) if s<0 .
What is the maximum sum of values you can get with a partition?
给定一个有 n 个数的数列 n,现在把它分成若干段。对于其中一段 a
l,a
l+1,…,a
r,设 s=a
l+a
l+1+…+a
r,则定义 a
l,a
l+1,…,a
r 一段的价值为:
-
(r−l+1) if s>0 ,
-
0 if s=0 ,
-
−(r−l+1) if s<0 .
显然,通过某些分段方式,可以使 a 中每段价值和最大,求这个最大价值。