Given the parameter k and the array [a 0 , 1 , a 2 , a 3 , ..., a n ], where a x determines the height of the relief, find the smallest amount of work necessary for the landscape to pass. The terrain is passable if the difference between two neighboring places is less than or equal to k. The height of the terrain at x can be changed, and the amount of work required is equal to the difference in height that you do. The heights 0 and n cannot be changed, and therefore some landscapes may be completely inaccessible.
I struggled with this for a while: this is what I have guessed so far: Of course, finding a solution (not considering the minimum amount of work that needs to be considered) is easy - take the βstepsβ from 0 to n , as in the diagram with k = 2 (red dots are the heights of the old terrain, gray for the new).
(The entrance for this particular locality will be: k = 2, [0, 2, 3, 2, 5, 4, 5, 7])
As you can see, the new landscape does not take into account the old territory and, therefore, the work necessary to convert the old into this one can be huge.
Determining whether a path exists is trivial: k> = | a 0 -a n | / n, but I have no idea how I will go about finding the optimal solution.
source share