起点的可行路径数量为1.

接着从上往下,从左往右遍历每个点。

从起点到每个点的可行路径数量  = 左边点的可行路径数量 + 上边点的可行路径数量

若该点为1,则可行路径数量为0

则最终可知结果。复杂度为O(m*n)

class Solution {
public:
int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
int m,n;
int pathnum[101][101];
memset(pathnum,0,sizeof(pathnum));
m = obstacleGrid.size();
n = obstacleGrid[0].size();
int i,j;
i = j = 0;

pathnum[0][0] = 1;
for(i = 0;i < m; i++){
for( j = 0;j < n; j++){
if(obstacleGrid[i][j] == 1){
pathnum[i][j] = 0;
}
else{
if(i != 0)
pathnum[i][j] += pathnum[i-1][j];
if(j != 0)
pathnum[i][j] += pathnum[i][j-1];
}
}
}
return pathnum[m-1][n-1];
}
};