# 不同路径 II

<p>一个机器人位于一个 <em>m x n </em>网格的左上角 （起始点在下图中标记为“Start” ）。</p>
<p>机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角（在下图中标记为“Finish”）。</p>
<p>现在考虑网格中有障碍物。那么从左上角到右下角将会有多少条不同的路径？</p>
<p><img src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0063.Unique%20Paths%20II/images/robot_maze.png"
        style="height: 183px; width: 400px;" /></p>
<p>网格中的障碍物和空位置分别用 <code>1</code> 和 <code>0</code> 来表示。</p>
<p> </p>
<p><strong>示例 1：</strong></p><img alt=""
    src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0063.Unique%20Paths%20II/images/robot1.jpg"
    style="width: 242px; height: 242px;" />
<pre><strong>输入：</strong>obstacleGrid = [[0,0,0],[0,1,0],[0,0,0]]<strong><br />输出：</strong>2<strong><br />解释：</strong>3x3 网格的正中间有一个障碍物。从左上角到右下角一共有 2 条不同的路径：<br />1. 向右 -> 向右 -> 向下 -> 向下<br />2. 向下 -> 向下 -> 向右 -> 向右</pre>
<p><strong>示例 2：</strong></p><img alt=""
    src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0063.Unique%20Paths%20II/images/robot2.jpg"
    style="width: 162px; height: 162px;" />
<pre><strong>输入：</strong>obstacleGrid = [[0,1],[0,0]]<strong><br />输出：</strong>1</pre>
<p> </p>
<p><strong>提示：</strong></p>
<ul>
    <li><code>m == obstacleGrid.length</code></li>
    <li><code>n == obstacleGrid[i].length</code></li>
    <li><code>1 <= m, n <= 100</code></li>
    <li><code>obstacleGrid[i][j]</code> 为 <code>0</code> 或 <code>1</code></li>
</ul>

## template

```python
class Solution(object):
	def uniquePathsWithObstacles(self, obstacleGrid):
		m, n = len(obstacleGrid), len(obstacleGrid[0])
		if m == 0:
			return 0
		dmap = [[0] * (n + 1) for _ in range(m + 1)]
		dmap[m - 1][n] = 1
		for i in range(m - 1, -1, -1):
			for j in  range(n - 1, -1, -1):
				if obstacleGrid[i][j] == 1:
					dmap[i][j] = 0
				else:
					dmap[i][j] = dmap[i][j + 1] + dmap[i + 1][j]
		return dmap[0][0]
# %%
s = Solution()
print(s.uniquePathsWithObstacles(obstacleGrid = [[0,1],[0,0]]))
```

## 答案

```python

```

## 选项

### A

```python

```

### B

```python

```

### C

```python

```