Dynamic programming for the shortest path with k edges