还是dp问题,注意障碍的处理即可
class Solution {
public:int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
int m=obstacleGrid.size(),n=obstacleGrid[0].size();
vector<vector<int>> dp(obstacleGrid.size(),vector<int> (obstacleGrid[0].size(),0));
int i=0;
while(i<m) {
if(obstacleGrid[i][0] == 0)
dp[i][0] = 1;
else
break;
i++;
}
int j=0;
while(j<n) {
if(obstacleGrid[0][j] == 0)
dp[0][j] = 1;
else
break;
j++;
}
for(int i=1;i<m;i++) {
for(int j=1;j<n;j++) {
if(obstacleGrid[i][j] == 1) {
dp[i][j] = 0;
continue;
}
else
dp[i][j] = dp[i-1][j] + dp[i][j-1];
}
}
return dp[m-1][n-1];
}
};