Let u and r be the distance to move in the up and right directions. u=y2-y1
and r=x2-x1.

We have to move a total of u+r units. So the answer would be (u+r)!/u!r!
since we are counting only the distinct paths.
Each path from (x1,y1) to (x2,y2)  may be expressed as a sequence of u+r
steps consisting of U or R.
If seq[i] has U then it means we moved up at the i th step. Similarly R is
for right. The number of distinct paths would be the number of distinct
arrangements of the sequence.

On Sat, Jun 23, 2012 at 11:05 AM, Gobind Kumar Hembram <gobind....@gmail.com
> wrote:

> Given two positions in a 2-D matrix, say (x1, y1) and (x2, y2) where
> x2>=x1 and y2>=y1. Find the total number of distinct paths between
> (x1, y1) and (x2, y2). You can only move in right direction i.e.
> positive x direction (+1, 0) or in up direction i.e. positive y
> direction (0, +1) from any given position.
>
> Example: If the given coordinates are  (3,3)  and (5,5), the number of
> distinct paths are 6 :  one going through 3,5 ; one going through 5,3
> and four going through 4,4.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to