题目如下:
解题思路:没啥好说的,用动态规划,很容易得到递推表达式: dp[m] [n]= dp[m-1][n] + dp[m][n-1]。
代码如下:
class Solution(object): def uniquePaths(self, m, n): """ :type m: int :type n: int :rtype: int """ dp = [[0 for x in range(m)] for x in range(n)] dp[0][0] = 1 for i in range(n): for j in range(m): if i-1 >=0: dp[i][j] += dp[i-1][j] if j-1 >=0: dp[i][j] += dp[i][j-1] #print dp return dp[n-1][m-1]