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 :

动态规划

63. Unique Paths II 动态规划的更多相关文章

  1. leetcode 62. Unique Paths 、63. Unique Paths II

    62. Unique Paths class Solution { public: int uniquePaths(int m, int n) { || n <= ) ; vector<v ...

  2. LEETCODE —— Unique Paths II [动态规划 Dynamic Programming]

    唯一路径问题II Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are ...

  3. 62. Unique Paths && 63 Unique Paths II

    https://leetcode.com/problems/unique-paths/ 这道题,不利用动态规划基本上规模变大会运行超时,下面自己写得这段代码,直接暴力破解,只能应付小规模的情形,当23 ...

  4. 【LeetCode】63. Unique Paths II

    Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are added to ...

  5. 63. Unique Paths II(有障碍的路径 动态规划)

    Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...

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

    A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...

  7. LeetCode OJ 63. Unique Paths II

    Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...

  8. 【LeetCode】63. Unique Paths II 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/unique-pa ...

  9. leetcode 63. Unique Paths II

    Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...

随机推荐

  1. python 判断对象是否相等以及eq函数

    当对两个点的实例进行值的比较时,比如p1=Point(1,1) p2=Point(1,2),判断p1==p2时__eq__()会被调用,用以判断两个实例是否相等.在上述代码中定义了只要x和y的坐标相同 ...

  2. 项目实践之工作流引擎基本文档!Activiti工作流框架中流程引擎API和服务详解

    流程引擎的API和服务 流程引擎API(ProcessEngine API)是与Activiti打交道的最常用方式 Activiti从ProcessEngine开始.在ProcessEngine中,可 ...

  3. 加载动画效果 HTML+ CSS

    加载动画效果 写在前面 在无限的时间的河流里,人生仅仅是微小又微小的波浪.--郭小川 实现效果 实现原理 通过2个伪元素来设置3条颜色边框 通过定位将3个圆弧边框层叠再一起,再通过旋转实现一个圆的效果 ...

  4. GO语言练习---对切片进行排序

    对整型切片进行选择排序 package main import "fmt" /*对切片排序*/ func SortSlice(slice []int) { for i := 0; ...

  5. 如何查看Oracle SID即instance_name 和 dbname区别

    SID 和  instance_name是一个实例名字db_name 是数据库名字搞清两个概念,数据库和实例 实例:实例是数据库启动时初始化的一组进程和内存结构 数据库:数据库则指的是用户存储数据的一 ...

  6. Jmeter- 笔记1 - 理论知识

    为什么不用loadrunner,lonadrunner免费最大并发用户50,再往上就要买license了. 性能输出结果不是bug 假如调试脚本没有出错,但运行脚本时,可能前期没有问题,但到后期偶尔/ ...

  7. typeof的作用及用法

    typeof的作用及用法 1.检查一个变量是否存在,是否有值. typeof在两种情况下会返回"undefined":一个变量没有被声明的时候,和一个变量的值是undefined的 ...

  8. 实时实例分割的Deep Snake:CVPR2020论文点评

    实时实例分割的Deep Snake:CVPR2020论文点评 Deep Snake for Real-Time Instance Segmentation 论文链接:https://arxiv.org ...

  9. 计算机网络-vlan划分

    1.VLAN的划分 (1)基于端口的VLAN: 交换机A上的1,2端口和交换机B上的3,4端口构成一个VLAN. 交换机A上的3,4端口和交换机B上的1,2端口构成一个VLAN. (2)基于MAC地址 ...

  10. mount 挂载操作

    windows系统显示光盘内容 光盘文件-------->光驱设备--------->双击访问CD驱动器(访问点) Linux系统显示光盘内容 光盘文件-------->光驱设备-- ...