dfs + 打表过不了,只能动态规划
int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
if (!obstacleGrid.size() || !obstacleGrid[0].size())
return 0;
int rows = obstacleGrid.size(), cols = obstacleGrid[0].size();
vector<vector<long long>> dp(rows, vector<long long>(cols, 0));
if (obstacleGrid[0][0] == 1)
return 0;
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
if (obstacleGrid[i][j] == 1)
continue;
if (i == 0 && j == 0)
dp[0][0] = 1;
else if (i == 0)
dp[i][j] = dp[i][j - 1];
else if (j == 0)
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = dp[i][j - 1] + dp[i - 1][j];
}
}
return dp[rows - 1][cols - 1];
}