Monday, 12 November 2012

Move block in matrix

Question:
Given a m*n matrix and a person is sitting in (0,0) box, and he has to go to the (m-1,n-1) box of the matrix .And the person can only go to right or down box from its current box position . We need to find out the number of ways he can reach from start to destination box .


Solution:
He needs to take total 'm-1 down' + 'n-1 right' steps
Its classical Permutation and Combination problem.
Refer to theorem 3 on this page intmath.com/counting-probability/3-permutations.php
Hence ans = (m+n-2)! / ((m-1)!*(n-1)!)

POST YOUR OPINION IF YOU HAVE BETTER SOLUTION

No comments:

Post a Comment

Your feedback is always appreciated.
I will try to reply to your queries as soon as time allows.
Please do not spam Spam comments will be deleted immediately upon our review.