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. java命令的本质逻辑揭秘

    前言 在日常编码中,有了ide的支持,我们已经很少直接在命令行中直接执行java XXX命令去启动一个项目了.然而我们有没有想过,一个简单的java命令背后究竟做了些什么事情?让我们看下下面几个简单的 ...

  2. 使用原生JS,实现鼠标点击爱心效果 !!!

    使用原生JS,实现鼠标点击爱心效果 !!! 引言: 在很多时候我们都需要实现鼠标点击出现图案或者文字这样的效果,对于用户而言,这样的体验是很极致的.其实实现起来也很简单,下面一起来学习一下吧.文末附上 ...

  3. 动态更换animator的animatorcontroller

    你可以这样 Animator animator = this.gameObject.GetComponent<Animator>(); animator.runtimeAnimatorCo ...

  4. 如何设计 API 接口,实现统一格式返回?

    文章目录: 目录 前后端接口交互 接口返回值约定 返回值规范 正确返回 错误返回 统一定义错误码 错误码规范 Controller 层如何用? 正确返回 错误返回 详细代码实现 错误码 Control ...

  5. GO学习-(31) Go语言操作Elasticsearch

    Elasticsearch 本文简单介绍了ES.Kibana和Go语言操作ES. Elasticsearch 介绍 Elasticsearch(ES)是一个基于Lucene构建的开源.分布式.REST ...

  6. 从“信息化”到“智慧化”,GVS视声将如何赋能智慧医院?

    4月23日-25日,2021年中华医院信息网络大会(CHINC)盛大举办,今年首次携手中国医院建筑与装备创新发展大会,同期同地亮相杭州国际博览中心,塑造了全新的"双引擎"品牌盛会. ...

  7. spring IOC DI AOP MVC 事务, mybatis 源码解读

    demo https://gitee.com/easybao/aop.git spring DI运行时序 AbstractApplicationContext类的 refresh()方法 1: pre ...

  8. STS或eclipse中导入新项目出现红色感叹号红色叉叉的问题

    maven项目 原因: jar包缺失 没有正确配置Maven仓库 解决: Window->Preferences->Maven->Installations->Add 添加你的 ...

  9. 性能工具之Jmeter小白入门系列之一

    一.简单了解 Apache JMeter The Apache JMeter application is open source software, a 100% pure Java applica ...

  10. mysqldump 使用规范

    数据库很重要,没有备份,数据丢失只能跑路.所以还是做好备份吧! 目录 一.工具介绍 二.工具特点 三.备份权限 四.工具使用限制 五.已知BUG 六.备份前注意事项 6.1 需要长时间备份或导入时,请 ...