we have to find min cost path in a mtrix from top left to bottom right.

Move allowed -> Right,left,Bottom,Up.

I know suitable approach will be using Dijkstra But can we do this using Dp because here we can move in all 4 direction ,If yes then How?

# | User | Rating |
---|---|---|

1 | tourist | 3686 |

2 | LHiC | 3330 |

3 | wxhtxdy | 3329 |

4 | Benq | 3315 |

5 | Um_nik | 3301 |

6 | sunset | 3279 |

7 | V--o_o--V | 3275 |

8 | yutaka1999 | 3190 |

9 | Radewoosh | 3179 |

10 | Petr | 3115 |

# | User | Contrib. |
---|---|---|

1 | Errichto | 193 |

2 | Radewoosh | 184 |

3 | rng_58 | 165 |

4 | PikMike | 163 |

5 | Vovuh | 159 |

6 | 300iq | 153 |

6 | majk | 153 |

8 | Petr | 148 |

9 | Um_nik | 147 |

10 | neal | 144 |

we have to find min cost path in a mtrix from top left to bottom right.

Move allowed -> Right,left,Bottom,Up.

I know suitable approach will be using Dijkstra But can we do this using Dp because here we can move in all 4 direction ,If yes then How?

↑

↓

Codeforces (c) Copyright 2010-2019 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jul/21/2019 18:52:35 (g1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

is cost value always non negative?

If you can move in all four directions, you have a graph with cycles and then you can't use dp.

If the cost values are non negative is it still true that we can't use dp.

Yes. Because what would dp transitions look like? There can be no cycles among them.

That's how I implemented it can it be more efficient. https://ideone.com/tvKC9r

Can anyone tell me what will be the time complexity of my solution ? I am using dijkstra on a matrix (in above soln) ?

Ffs, make a loop over adjacent cells. Don't repeat the same piece of code 4 times.

What is the number of states (vertices of a graph)? What is the number of transitions (edges)? And finally, what is the complexity of Dijkstra?