Skip to main content
1 of 3

fniding lowest cost path - dynamic

this is my first post here, well i have a problem. I have to write a dynamic algorithm for finding lowest cost path. So i have a points that i have to visit. I can jump only between points by distance - 5 I have an array of distance from 0-point for example (1 3 5 10 15 20 21 22). Each move cost me 1. So the best path will be to move 1->5->15->20->22 (3 and 21 i can skeep).

Can you guys give me so hints, how to program it dynamicly? I was thinking to make something like this: Find the solution for array[0] and array[1] (that's easy there is only one solution from to 1 (1->3)) then add array[2], and find the best solution(1->5 also there is a solution 1->3->5 but that's gonna cost me 2 moves) then for 4 points, 5 etc.

But don't know how to start to make my algorithm to be written correct and dynamic. I know i can make greedy algorithm, but that's not the point of the task... Can u give me any hints? How to start? How to keep solutions? and find the best ones?