Блог пользователя caioaao

Автор caioaao, 10 лет назад, По-английски

I've been trying to understand how to solve this problem on UVa: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=441&page=show_problem&problem=3969

Abridged problem statement: You have N piles in different heights, each pile having a weight W. You can only move a pile if the next X is bigger than the pile you are moving, and each move costs W * Δ Height. You want to turn the N piles into K piles with the minimum cost possible (you can only move one pile to another place where there was a pile). constraints: 1 ≤ K ≤ N ≤ 1000 and W ≤ 106

I've found lots of explanations (mostly in spanish and chinese), and all of them say "it's easy to see a DP solution of O(n*n*k), but that would TLE..." yeah, I can see one DP solution in O(n*n*k), but I can't understand their recursion and, more specifically, how to turn that into line equations and how to apply convex hull trick on it.

I've never solved any problem that needed convex hull trick or any DP optimization at all, so I'm quite a noob here. Any materials (apart from PEGWiki's article on convex hull trick), like simple problems solvable with it, are apreciated.

Thanks!

References (didn't help me, but maybe some of you can make sense out of it):

  • Проголосовать: нравится
  • +9
  • Проголосовать: не нравится

»
10 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится
»
10 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

Simpler problem: SPOJ — NKLEAVES

And if you need some explanation about NKLEAVES, read here

Hope it helps!

»
8 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

This problem also can be solved using Divide and Conquer Optimization. Code