I recently read the article from PEG Wiki about the convex hull trick, which can be applied to speed up dynamic programming algorithms (Link to the website) . This optimisation can only apply when certain conditions are met. Surprisingly, at the end of the article I read that we can achieve a fully dynamic variant of the trick (meaning that there are no conditions of applicability) if we store the lines in a std::set
. Although I have understood the approach mentioned, I always fail when I try to implement it. Could someone point me to an implementation of the dynamic convex hull trick, and some problems where I can practice it? Thanks in advance.
Here: http://codeforces.net/blog/entry/11155#comment-162462
Thank you very much! This is exactly what i was looking for. By the way, I found a really nice problem for everyone who is interested in practicing this technique: http://www.spoj.com/problems/GOODG/
I am the author of the dynamic convex hull code dj3500 linked to, so please write me if you find any problems :)
Thank you very much :)
Just as a warning for future readers.
You don't need the fully dynamic variant to solve this problem. You can solve it easily with a different approach. :)
Here are many good convex-hull trick problems (also in the comments): http://codeforces.net/blog/entry/8219
Here is my alternative implementation. Hope this will help somebody. Note: this class can be used to find both max and min values.
Thanks a lot!
This helped me a lot, thanks for all the work you put in.
Hey , I wanted to ask questions about your implementation!
Does your Code needs any specific condition that is decreasing slopes or increasing values of x?
thank you very much