I am stuck with this problem for more than 2 years. :(
Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3871
Lightoj categorized this problem under DP and Segment tree. But I have no idea how to plug this two topic in the solution. Can anyone provide me the solution in descriptive way? :)
I found this : http://morris821028.github.io/2014/12/09/uva-12440/ Using google translate i think you can understand most of it. It's a worst-case O(n^2) solution but fast enough to get AC. Then i changed the code to make it O(nlogn) using multiset. http://paste.ofcode.org/HL4mwrQXh8Xk8jZDFNGv3r
It has been discussed in a previous blog
http://mirror.codeforces.com/blog/entry/12393
Can you explain in this solution how do we use segment tree to get min of S(k) + H(k + 1, n)?
It seems like it's similar to 2D Segment Tree because query has 3 parameters not 2.
Is there a way to do it in O(logn)?