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. MySql类似Oracle的dual虚拟表

    在mysql里也存在和oracle里类似的dual虚拟表:官方声明纯粹是为了满足select ... from...这一习惯问题,mysql会忽略对该表的引用. 你可千万注意了: select * f ...

  2. [NHibernate]HQL查询

    目录 写在前面 文档与系列文章 查询的几种方式 HQL查询 一个例子 总结 写在前面 上篇文章介绍了nhibernate在项目中的基本配置,包括数据库连接字符串的设置,映射文件的配置及需注意的地方,这 ...

  3. visio二次开发初始化问题

    (转发请注明来源:http://www.cnblogs.com/EminemJK/) 问题: axDrawingControl1初始化失败((System.ComponentModel.ISuppor ...

  4. 问题解决:psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

    错误提示: psql: could not connect to server: No such file or directory Is the server running locally and ...

  5. C# *= 运算顺序

    a *= a + b *c; 不管等号右边有没有括号,总是先算右边: 即等价于 a = a *(a + b*c); using System; using System.Collections.Gen ...

  6. word20161206

    D-channel / D 信道 DACL, discretionary access control list / 自由访问控制列表 daily backup / 每日备份 Data Communi ...

  7. R-FCN、SSD、YOLO2、faster-rcnn和labelImg实验笔记(转)

    https://ask.julyedu.com/question/7490 labelImg:https://github.com/tzutalin/labelImg

  8. 打造smali代码库辅助分析

    打造smali代码库辅助分析 在分析Android应用程序的时候,我们往往会插入代码重打包apk来辅助我们分析的工作 一个比较取巧的方法就是先用java写好代码以及相关的调用之后, 然后直接扣出代码 ...

  9. Python 开发轻量级爬虫08

    Python 开发轻量级爬虫 (imooc总结08--爬虫实例--分析目标) 怎么开发一个爬虫?开发一个爬虫包含哪些步骤呢? 1.确定要抓取得目标,即抓取哪些网站的哪些网页的哪部分数据. 本实例确定抓 ...

  10. Xcode常用快捷键(持续更新-20160811)

    前言 专门花时间记Xcode快捷键,我觉得没必要,一时记住,不久又会忘记. 用到才记. Xcode常用快捷键 新建 shift + cmd + n     新建项目 cmd + n           ...