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. Java Web学习笔记8

    上下文参数(context-param) 由于init-param是配置在<servlet>标签里的,只能有这个Servlet来读取,因此它不是全局的参数,不能被其他的Servlet读取. ...

  2. 认识VTK工作原理

    VTk通过数据流实现变信息为图形数据的. 数据流一般为:source-filter--mapper--actor--render--renderwindow--interactor. 要理解工作原理, ...

  3. mysql安装配置

    MySQL 是最流行的关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle公司. MySQL所使用的SQL语言是用于访问数据库的最常用标准化语言. MySQL由于其体积小.速度快 ...

  4. NOSDK--一键打包的实现(二)

    Android.mk文件,位置在android工程/jni目录下,是android工程中的makefile文件,这里我们简称它为mk文件. 1.2 自动刷新mk文件的脚本介绍 这一节介绍mk文件的自动 ...

  5. 浅析Java中的final关键字

    浅析Java中的final关键字 谈到final关键字,想必很多人都不陌生,在使用匿名内部类的时候可能会经常用到final关键字.另外,Java中的String类就是一个final类,那么今天我们就来 ...

  6. shell--3.运算符

    1.注意 原生bash不支持简单的数学运算,但是可以用其它命令来实现如 awk 和expr ,expr最常用 val=`expr 2 + 3` echo "结果 ${val}" # ...

  7. Node.js入门学习笔记(二)

    函数传递 举例来说,你可以这样做: function say(word) {      console.log(word);  }  function execute(someFunction, va ...

  8. ubuntu16.04下安装cuda8.0

    一.首先安装NVIDIA显卡驱动 通过NVIDIA-Linux-x86_64-367.44.run文件安装. 1. 添加 PPA. sudo add-apt-repository ppa:graphi ...

  9. python基础一

    1.1 Python优点 1.简单.优雅.明确 2.强大的模块三方库 3.易移植 4.面向对象 5.可扩展(c\java\c#...) 1.2 Python缺点 1.代码不能加密 2.速度慢   1. ...

  10. Pycharm用Ctrl+鼠标滚轮调节代码字体大小

     File --> Setting --> Editor --> General --> 勾选Change font size (zoom) with Ctrl+Mouse W ...