### vkditya0997's blog

By vkditya0997, history, 5 years ago,

Problem Statement : Click
I'm not able to arrive at the dp state.
But there were some comments on the announcement Post
It mentioned

dp[ i ][ j ] = max( dp[ i ][ j - 1 ] , presum[ j ] - presum[ j - m ] + dp[ i - 1 ][ j - m ] );


Some one please explain this state?
Thank you

• +1

 » 5 years ago, # |   +2 Dp[I][j] = maximum sum of j non intersecting segments of length m from first I elements
 » 5 years ago, # | ← Rev. 3 →   +2 dp[i][j] stands for what is the max value we can get when we reach the j th element and using exactly i pairs already.If there is not a pair between element j — m + 1 and j (inclusively), then the value will be dp[i][j — 1].Otherwise, if there is a pair chosen between element j — m + 1 and j, then the value will be: dp[i — 1][j — m] + (presum[j] — presum[j — m]) (which is the total sum of value in segment from j — m + 1 to j)You can check my implementation based on the formula you provide.http://www.codeforces.com/contest/467/submission/18229054