1.题目要求:
2.题目代码:
class Solution {
public:int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {//创建dp数组的含义vector<vector<int>> dp;dp.resize(obstacleGrid.size());for(int i = 0;i < dp.size();i++){dp[i].resize(obstacleGrid[i].size());}//1.dp数组下标的含义//2.递推公式//3.初始化//开始进行初始化int j = 0;for(j = 0;j < dp[0].size();j++){if(obstacleGrid[0][j] != 1){dp[0][j] = 1;}else{break;}}while(j < dp[0].size()){dp[0][j] = 0;j++;}int i = 0;for(i = 0;i < dp.size();i++){if(obstacleGrid[i][0] != 1){dp[i][0] = 1;}else{break;}}while(i < dp.size()){dp[i][0] = 0;i++;}//确定遍历顺序for(i = 1;i < dp.size();i++){for(j = 1;j < dp[i].size();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[dp.size() - 1][dp[0].size() - 1];}
};