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 middle of a 3x3 grid as illustrated below.

[
[0,0,0],
[0,1,0],
[0,0,0]
]

The total number of unique paths is 2.

Note: m and n will be at most 100.

简单的动态规划问题

class Solution {
public:
int dp[][];
int uniquePathsWithObstacles(vector<vector<int> > &obstacleGrid) {
memset(dp,,sizeof(dp));
dp[][]=obstacleGrid[][] == ? :;
int n = obstacleGrid.size(), m = obstacleGrid[].size();
for(int i = ; i < n; ++ i )
dp[i][] = obstacleGrid[i][] == ? : dp[i-][];
for(int i = ; i < m; ++ i )
dp[][i] = obstacleGrid[][i] == ? : dp[][i-];
for(int i = ; i < n ; ++ i){
for(int j = ; j < m ; ++ j){
dp[i][j] = obstacleGrid[i][j] == ? : dp[i-][j] + dp[i][j-];
}
}
return dp[n-][m-];
}
};

Leetcode Unique Paths II的更多相关文章

  1. LeetCode: Unique Paths II 解题报告

    Unique Paths II Total Accepted: 31019 Total Submissions: 110866My Submissions Question Solution  Fol ...

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

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

  3. LEETCODE —— Unique Paths II [Dynamic Programming]

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

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

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

  5. [leetcode]Unique Paths II @ Python

    原题地址:https://oj.leetcode.com/problems/unique-paths-ii/ 题意: Follow up for "Unique Paths": N ...

  6. [Leetcode] unique paths ii 独特路径

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

  7. [LeetCode] Unique Paths && Unique Paths II && Minimum Path Sum (动态规划之 Matrix DP )

    Unique Paths https://oj.leetcode.com/problems/unique-paths/ A robot is located at the top-left corne ...

  8. 动态规划小结 - 二维动态规划 - 时间复杂度 O(n*n)的棋盘型,题 [LeetCode] Minimum Path Sum,Unique Paths II,Edit Distance

    引言 二维动态规划中最常见的是棋盘型二维动态规划. 即 func(i, j) 往往只和 func(i-1, j-1), func(i-1, j) 以及 func(i, j-1) 有关 这种情况下,时间 ...

  9. [Leetcode Week12]Unique Paths II

    Unique Paths II 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/unique-paths-ii/description/ Descrip ...

随机推荐

  1. asp.net core 使用EF7 Code First 创建数据库,同时使用命令创建数据库

    1.首先下载vs2015的Asp.Net Core(RC2)的插件工具(https://www.microsoft.com/net/core#windows)2.创建一个asp.net Core的项目 ...

  2. 2015.4.21 实现一般免登陆,微博QQ分享,字体自适应等

    1.实现一般的登录验证和免登陆: 解决方法:node方法代码,nodeJS实现的session模块,不完整,但能用,仅供参考. 语言无所谓,session的机制都是一样的,实现不一样而已,:   2. ...

  3. 自动化运维工具Ansible详细部署 (转载)

    自动化运维工具Ansible详细部署 标签:ansible 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://sofar.blog. ...

  4. APP常用字体

    font-family:Microsoft YaHei,Helvitica,Verdana,Tohoma,Arial,san-serif;

  5. PHP打印测试,PHP调试技巧

    第一步: 在 php.ini 中,将 display_errors 设置为 On: 第二步: 在 框架的 开始处,添加如下代码: <?php if (isset($_GET['debug'])) ...

  6. CentOS6.3安装MongoDB2.2 及 安装PHP的MongoDB客户端

    下载源码:(放到 /usr/local/src 目录下) 到官网 http://www.mongodb.org/downloads 下载源码 https://fastdl.mongodb.org/li ...

  7. Java 串口通信

    在Windows系统下,用Java开发串口通信相关的程序时,需要用到几个文件. (1)win32com.dll 要放在jdk\jre\bin目录下. (2)comm.jar 和javax.comm.p ...

  8. python的os模块

    1.得到当前工作目录,即当前Python脚本工作的目录路径: os.getcwd() 2.返回指定目录下的所有文件和目录名:os.listdir() 3.函数用来删除一个文件:os.remove() ...

  9. 4. UIButton的使用

    1. UIButton的初认识 来自:http://www.cnblogs.com/mcj-coding/p/5103891.html QQ:853740091 1.1 UIButton 是iOS 开 ...

  10. ping命令执行过程详解

    [TOC] ping命令执行过程详解 机器A ping 机器B 同一网段 ping通知系统建立一个固定格式的ICMP请求数据包 ICMP协议打包这个数据包和机器B的IP地址转交给IP协议层(一组后台运 ...