PROBLEM LINK:
https://www.codechef.com/TNP52021/problems/TNP505
Author: Setter’s name
Tester: Tester’s name
Editorialist: Editorialist’s name
DIFFICULTY : EASY
PREREQUISITES:
Nill
PROBLEM:
At the Maths Championship, Benjamin was given a problem on the matrix. The problem is to count all the possible paths from top left to bottom right of a MxN matrix with the constraints that from each cell you can either move to right or down.
#EXPLANATION:
Let the given input 3*3 matrix is filled as such:
A B C
D E F
G H I
The possible paths which exists to reach ‘I’ from ‘A’ following above conditions are as follows:
ABCFI, ABEHI, ADGHI, ADEFI, ADEHI, ABEFI
#SOLUTION:
def numberOfPaths(m, n): #python 3
if(m == 1 or n == 1):
return 1
return numberOfPaths(m-1, n) + numberOfPaths(m, n-1)
Driver program to test above function
if name==“main”:
m,n=map(int,input().split())
print(numberOfPaths(m, n))