有一个机器人的位于一个 m × n 个网格左上角。
机器人每一时刻只能向下或者向右移动一步。机器人试图达到网格的右下角。
问有多少条不同的路径?
样例
Example 1:
Input: n = 1, m = 3
Output: 1
Explanation: Only one path to target position.
Example 2:
Input: n = 3, m = 3
Output: 6
Explanation:
D : Down
R : Right
1) DDRR
2) DRDR
3) DRRD
4) RRDD
5) RDRD
6) RDDR
注意事项
n和m均不超过100
class Solution {
public:
/**
* @param m: positive integer (1 <= m <= 100)
* @param n: positive integer (1 <= n <= 100)
* @return: An integer
*/
int uniquePaths(int m, int n) {
// write your code here
int result[m][n];
for(int i=0;i<m;i++)
{
for (int j = 0; j < n; j++) {
/* code */
if(i==0||j==0) result[i][j]=1;
else result[i][j]=result[i-1][j]+result[i][j-1];
}
}
return result[m-1][n-1];
}
};```