Given a set of n
stones, arranged in a row at equal distances from each other. The stones are numbered from 0
to n-1
. A frog that is on stone number 0
has to get to stone number n-1
.
A jump is a move from stone i
to stone j
( i<j
). Such a jump has length equal to j-i
. The maximum jump length of the frog depends on its energy level (which cannot drop below 0). A jump of length j-i
costs the frog j-i
energy. For example, with an initial energy of 3, a frog on stone 0
can jump to stone 3
at most.
On some stones, there may be worms, which add energy to the frog. If the frog jumps on a stone with a worm on it, it MUST eat the worm. The list T[0...n-1]
contains the energy values of the worms on the corresponding stones. If there is no worm on the stone, this is equivalent to a value of 0.
The frog starts with 0 Energy, but it is guaranteed that there is a worm on stone number 0
.
Given a list T
, the task is to return a list of the indexes of the stones on which the frog has been, before getting to stone n-1
. However, this must be the shortest possible list. In some cases there may be more than one solution, whichever is accepted. It is guaranteed that always the frog will be able to get to stone n-1
.
Example no. 1:
For T = [3, 0, 2, 1, 0, 2, 5, 0] the answer is [0, 2, 5].
Example no. 2:
For T = [7, 0, 0, 1, 0, 3, 0, 6, 0, 0, 0, 0, 0, 0, 0] the answer is [0, 3, 7] or [0, 5, 7].
I have no idea how to approach this problem, all I know is that I probably need to use some dynamic programming or greedy algorithm here, but how? Anyone have any ideas?