Number of possible paths using combinations

·

1 min read

robot.png

By how many ways can robot reach to its destination?

according to diagram there are 28 ways .But how?

at current position robot can have atmost 6 RIGHT MOVES & 2 DOWN MOVES.

RRRRRRDD

So answer is nothing but total ways in which RRRRRRDD can be arranged

and formula for that is nCr(8)/((nCr(6))*(nCr(2))) which is 28

unsigned int factorial(unsigned int n)
{
     if(n == 0)
          return 1;
    unsigned int i = n, fact = 1;
    while (n / i != n)
    {
        fact = fact * i;
        i--;
    }
    return fact;
}



int uniquePaths(int m, int n){
    return (factorial(m+n-2))/((factorial(m-1))*(factorial(n-1)));
}