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 动态规划相关推荐

  1. 【动态规划】LeetCode 63. Unique Paths II

    LeetCode 63. Unique Paths II Solution1:我的答案 在哪里做过这题? class Solution { public:int uniquePathsWithObst ...

  2. 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的题目就很轻松 ...

  3. [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 ...

  4. 63. Unique Paths II

    和Unique paths是一样的 1 public int uniquePathsWithObstacles(int[][] obstacleGrid) { 2 if(obstacleGrid == ...

  5. [LeetCode]--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

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

  7. 63. Unique Paths II 不同路径 II

    Title 一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为"Start" ). 机器人每次只能向下或者向右移动一步.机器人试图达到网格的右下角(在下图中标记为 ...

  8. leetcode63. Unique Paths II

    题目要求 Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. H ...

  9. Unique Paths II leetcode java

    题目: Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. H ...

最新文章

  1. matlab2018a安装后帮助文档打不开解决方法
  2. 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
  3. java泛型面试_Java泛型面试问题
  4. 单链表实现反转的三种方法
  5. 引介 | RLP 编码和解码
  6. Go 存储基础 — 内存结构体怎么写入文件?
  7. Linux —— 常见指令及其英文全称
  8. iBatis和Hibernate浅析
  9. LogServer日志详解
  10. MATLAB点云重采样,PCL点云曲面重采样三种方法:上采样,下采样,均匀采样
  11. Mac安装Python并使用GUI界面设计
  12. windows必备的驱动软件推荐
  13. 产品经理学习——卡诺模型
  14. Vue3快速学习、vue3视频学习、vue3实例上手教程
  15. 百家讲坛之易中天品三国MP3全集
  16. UWB基本原理分析2
  17. 每时每刻做最有效的seo操作
  18. 解析拼手气红包金额划分算法
  19. 可能是目前为止全网最好的介绍分布式系统原理的中文文档!
  20. 什么是我的java.net.SocketException:连接重置?

热门文章

  1. cocos2d-lua-win
  2. java并发编程之美-阅读记录2
  3. Sql 行转列 STUFF
  4. java中debug使用
  5. WPF---Xaml中改变ViewModel的值
  6. OpenCV——素描
  7. tar 备份时如何保持权限
  8. php动态删除输入框,jQuery实现动态添加和删除input框实例代码
  9. python持久化存储文件操作
  10. 问题 G: 最小的回文数