Consider a grid formed by n vertices vertically down, and m vertices horizontally right. Your starting point is at the top left vertex. Your destination is the bottom right vertex. You are permitted at each vertex to choose to move down or right, that is in the direction towards the destination. You are not to move on what constitutes a back step like moving left or up. If you hit the bottom boundary, or right boundary take it to be given there is only 1 way to the destination, that is following along the boundary.
Ex: in a 2x2 grid there are two ways. One way: First down, then right. The other way: First right, then down.
4x3 has 10 ways
6x5 has 126 ways
This problem can be solved using dynamic programming but there are other methods too.
Solution Stats
Problem Comments
5 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers80
Suggested Problems
-
Determine Whether an array is empty
808 Solvers
-
Find a subset that divides the vector into equal halves
400 Solvers
-
466 Solvers
-
Let's get back to school, and create multiplication tables
236 Solvers
-
4490 Solvers
More from this Author10
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
It would be more elegant to define the solution for the 1x1 case as 1 rather than 0.
agree, but will leave as so, so as to not affect submitted solutions.
I disagree with the base case. A 1x1 matrix has 1 path. And, the empty matrix has no path (zero).
The first test case has been changed from 0 to 1 without rescoring past solutions.
Very interesting problem when you think about it.