Count Paths Grid
Python
Hard
3 views
Problem Description
Read m n. Write function ways(m,n) that returns number of paths from (0,0) to (m-1,n-1) moving only right or down.
Input Format
One line: m n.
Output Format
One integer ways.
Official Solution
import sys
p=sys.stdin.read().strip().split()
if len(p)<2: sys.exit(0)
m=int(p[0]); n=int(p[1])
def ways(a,b):
dp=[1]*b
for _ in range(1,a):
for j in range(1,b):
dp[j]+=dp[j-1]
return dp[-1]
sys.stdout.write(str(ways(m,n)))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!