62. 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?


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

题目描述:统计从矩阵左上角到右下角的路径总数,每次只能向右或者向下移动分析:先举例再总结规律,第一列的路径只能有一条,第一行同理。dp[1][1] 就有两条,上面一条,左边一条。所以得到公式 dp[i][j]=dp[i-1][j]+dp[i][j-1]



原文地址:https://www.cnblogs.com/shaer/p/10520384.html

时间: 2024-08-30 04:18:10

62. Unique Paths(矩阵的总路径数)的相关文章

刷题62. Unique Paths

一.题目说明 题目62. Unique Paths,在一个m*n矩阵中,求从左上角Start到右下角Finish所有路径.其中每次只能向下.向右移动.难度是Medium! 二.我的解答 这个题目读读题目,理解后不难.定义一个dp[m][n],初始化最后一列为1,最后一行为1,然后循环计算到dp[0][0]就可以了. 代码如下: class Solution{ public: int uniquePaths(int m,int n){ vector<vector<int>> dp(m

LeetCode --- 62. Unique Paths

题目链接: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 (ma

[Leetcode]@python 62. Unique Paths

题目链接:https://leetcode.com/problems/unique-paths/ 题目大意:给定n.m,在mxn的矩阵中,从(0,0)走到(m-1,n-1)一共有多少种法(只能往下和往右走) 解题思路:从(0,0)到(m-1,n-1)一共要走m - 1次向下,n-1次向右.也就是在n + m - 2次中选出m-1次向下,也就是C(m + n - 2,m-1) class Solution(object): def uniquePaths(self, m, n): ""&

62. Unique Paths i &amp; ii

62. 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 (mar

leetCode 62.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 t

【一天一道LeetCode】#62. Unique Paths

一天一道LeetCode系列 (一)题目 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

LeetCode 62. Unique Paths Java

题目: 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'

LeetCode OJ:Unique Paths II(唯一路径II)

Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How many unique paths would there be? An obstacle and empty space is marked as 1 and 0 respectively in the grid. For example, There is one obstacle in the middl

[LeetCode] Unique Paths II 不同的路径之二

Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How many unique paths would there be? An obstacle and empty space is marked as 1 and 0 respectively in the grid. For example, There is one obstacle in the middl