Football Player – Total Dribble Paths

         Football Player – Total Dribble Paths 

A football coach wants his team to improve their dribbling skills. So he sets up a R * C grid, where R is the number of rows and C is the number of columns. From any given cell, a player can only dribble to the right cell or bottom cell.
A player always starts from top left most cell and must end at bottom right most cell where he can collect the reward if he has dribbled according to the rules above.
The program must accept R, C and print the total number of possible paths P in which a player can reach the destination.
Input Format:
The first line contains R.
The second line contains C.
Output Format:
The first line contains P.
Boundary Conditions:
1 <= R, C <= 100
Example Input/Output 1:
Input:
2
3
Output:
3
Example Input/Output 2:
Input:
3
3
Output:
6
Example Input/Output 3:
Input:
25
21
Output:
102758710
Code:

#include <iostream>
using namespace std;
int num(int m,int n)
{
    int count[m][n];
    int i,j;
    for(i=0;i<m;i++)
        count[i][0]=1;
    for(int j=0;j<n;j++)
        count[0][j]=1;
    for(int i=1;i<m;i++)
        {
            for(int j=1;j<n;j++)
                count[i][j]=count[i-1][j]+count[i][j-1];
        }
    return count[m-1][n-1];
}
int main(int argc, char** argv)
{
int r,c;
cin>>r>>c;
cout<<num(r,c);

}
or
int num(int m,int n)
    {
        if(m==1||n==1)
            return 1;
        return num(m-1,n)+num(m,n-1);
    }

Do Follow for More Solutions!!!!

 Python:

import sys
if __name__ == ‘__main__’:
    n,m=int(input()),int(input())
    c= [[0 for _ in range(m)] for _ in range(n)]
    for i in range(n):
        c[i][0]=1
    for j in range(m):
        c[0][j]=1
     
    for i in range(1,n):
        for j in range(m):
            c[i][j] = c[i-1][j] + c[i][j-1]
     
    print(c[n-1][m-1])


Java:

import java.util.*;
import java.math.BigInteger;
public class Hello {
    public static void main(String[] args) {
int r,c,i,j;
Scanner sc=new Scanner(System.in);
r=sc.nextInt();
c=sc.nextInt();
BigInteger[][] m=new BigInteger[r][c];
for(i=0;i<r;i++)
{
    for(j=0;j<c;j++)
    {
        m[i][0]=BigInteger.valueOf(1);
        m[0][j]=BigInteger.valueOf(1);
    }
}
for(i=1;i<r;i++)
{
    for(j=1;j<c;j++)
    {
        m[i][j]=m[i-1][j].add(m[i][j-1]);
    }
}
System.out.println(m[r-1][c-1]);
    }
}



One Comment

Add a Comment

Your email address will not be published. Required fields are marked *