I\'ve learnt a dynamic programming algorithm to find the \"cheapest\" path from A to B. Each sub path has an associated cost.
Each corner is calculated using
Try looking for "shortest path" algorithms, but there is a catch.
Many shortest-path searches use estimated distance to goal as a heuristic, which often has to satisfy certain conditions. A*, for example, uses a distance-to-goal estimation function, and is guaranteed to find the shortest path if it never underestimates the distance to the goal. Since you're looking for the path with lowest arbitrary cost, you won't have that sort of heuristic easily available. Also, you know the length of the path, so algorithms like iterative deepening aren't going to be useful.
Any deterministic algorithm, like Dijkstra's algorithm, should work fine.