Files
2020-08-07 17:06:53 +08:00

44 lines
1.4 KiB
Markdown
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# [62. Unique Paths](https://leetcode.com/problems/unique-paths/)
## 题目
A robot is located at the top-left corner of a *m* x *n* grid (marked 'Start' in the diagram below).
The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).
How many possible unique paths are there?
![](https://assets.leetcode.com/uploads/2018/10/22/robot_maze.png)
Above is a 7 x 3 grid. How many possible unique paths are there?
**Note:** *m* and *n* will be at most 100.
**Example 1:**
Input: m = 3, n = 2
Output: 3
Explanation:
From the top-left corner, there are a total of 3 ways to reach the bottom-right corner:
1. Right -> Right -> Down
2. Right -> Down -> Right
3. Down -> Right -> Right
**Example 2:**
Input: m = 7, n = 3
Output: 28
## 题目大意
一个机器人位于一个 m x n 网格的左上角 起始点在下图中标记为“Start” 。机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角在下图中标记为“Finish”。问总共有多少条不同的路径
## 解题思路
- 这是一道简单的 DP 题。输出地图上从左上角走到右下角的走法数。
- 由于机器人只能向右走和向下走,所以地图的第一行和第一列的走法数都是 1地图中任意一点的走法数是 `dp[i][j] = dp[i-1][j] + dp[i][j-1]`