题目:
有一个XxY的网格,一个机器人只能走格点且只能向右或向下走,要从左上角走到右下角。请设计一个算法,计算机器人有多少种走法。
class Robot:
def countWays(self, x, y):
# write code here
if x<1 or y<1:
return None
mat = [[1 for i in range(y)] for j in range(x)]
mat[0][0] = 0
for row in range(1,x):
for col in range(1,y):
mat[row][col] = mat[row-1][col] + mat[row][col-1]
return mat[x-1][y-1]