A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).
The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid
How many possible unique paths are there?
Note: m and n will be at most 100.
DP 最典型迷宫问题
class Solution {
public:
int uniquePaths(int m, int n) {
int ans[100][100],i,j;
//ans[0][0] = 0;
for(i=0;i<m;i++){
ans[i][0] = 1;
}
for(i=0;i<n;i++){
ans[0][i] = 1;
}
for(i=1;i<m;i++){
for(j=1;j<n;j++){
ans[i][j] = ans[i-1][j]+ans[i][j-1];
}
}
return ans[m-1][n-1];
}
};