63. Unique Paths II 动态规划
description:
https://leetcode.com/problems/unique-paths/
机器人从一堆方格的左上角走到右下角,只能往右或者往下走 ,问有几种走法,这个加了难度,在矩阵中加了障碍物
Note:
Example:
Example 1:Input:
[[0,0,0],[0,1,0],[0,0,0]
]
Output: 2
Explanation:
There is one obstacle in the middle of the 3x3 grid above.
There are two ways to reach the bottom-right corner:
1. Right -> Right -> Down -> Down
2. Down -> Down -> Right -> Right
answer:
class Solution {
public:int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {if (obstacleGrid.empty() || obstacleGrid[0].empty() || obstacleGrid[0][0] == 1) return 0;int m = obstacleGrid.size(), n = obstacleGrid[0].size();vector<vector<long>> dp(m + 1, vector<long>(n + 1, 0)); //比实际大一圈是为了处理左边和上边两个边的边缘问题dp[0][1] = 1; // 初始化for (int i = 1; i <= m; ++i) {for (int j = 1; j <= n; ++j) {if (obstacleGrid[i - 1][j - 1] != 0) continue; //如果是障碍则略过dp[i][j] = dp[i - 1][j] + dp[i][j - 1];}}return dp[m][n];}
};
relative point get√:
hint :
动态规划
转载于:https://www.cnblogs.com/forPrometheus-jun/p/11336701.html
63. Unique Paths II 动态规划相关推荐
- 【动态规划】LeetCode 63. Unique Paths II
LeetCode 63. Unique Paths II Solution1:我的答案 在哪里做过这题? class Solution { public:int uniquePathsWithObst ...
- 63. Unique Paths II and 64. Minimum Path Sum
文章目录 1 63 Unique Paths II 1.1 题目描述 1.2 动态规划解决 2 64. Minimum Path Sum 2.1 题目理解 2.2 动态规划 这一遍刷dp的题目就很轻松 ...
- [Lintcode]115. Unique Paths II/[Leetcode]63. Unique Paths II
115. Unique Paths II/63. Unique Paths II 本题难度: Easy/Medium Topic: Dynamic Programming Description Fo ...
- 63. Unique Paths II
和Unique paths是一样的 1 public int uniquePathsWithObstacles(int[][] obstacleGrid) { 2 if(obstacleGrid == ...
- [LeetCode]--63. Unique Paths II
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- LeetCode 63. Unique Paths II
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- 63. Unique Paths II 不同路径 II
Title 一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为"Start" ). 机器人每次只能向下或者向右移动一步.机器人试图达到网格的右下角(在下图中标记为 ...
- leetcode63. Unique Paths II
题目要求 Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. H ...
- Unique Paths II leetcode java
题目: Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. H ...
最新文章
- matlab2018a安装后帮助文档打不开解决方法
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- java泛型面试_Java泛型面试问题
- 单链表实现反转的三种方法
- 引介 | RLP 编码和解码
- Go 存储基础 — 内存结构体怎么写入文件?
- Linux —— 常见指令及其英文全称
- iBatis和Hibernate浅析
- LogServer日志详解
- MATLAB点云重采样,PCL点云曲面重采样三种方法:上采样,下采样,均匀采样
- Mac安装Python并使用GUI界面设计
- windows必备的驱动软件推荐
- 产品经理学习——卡诺模型
- Vue3快速学习、vue3视频学习、vue3实例上手教程
- 百家讲坛之易中天品三国MP3全集
- UWB基本原理分析2
- 每时每刻做最有效的seo操作
- 解析拼手气红包金额划分算法
- 可能是目前为止全网最好的介绍分布式系统原理的中文文档!
- 什么是我的java.net.SocketException:连接重置?