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]
] he total number of unique paths is 2. Note: m and n will be at most 100.

  同Unique Paths的DP类似。

class Solution {
public:
int uniquePathsWithObstacles(vector<vector<int> > &obstacleGrid) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int m = obstacleGrid.size();
int n = obstacleGrid[].size();
vector<vector<int>> grid(m, vector<int>(n,));
for(int i = ; i< n; i++)
if(obstacleGrid[][i] ==) grid[][i] = ;
else break;
for(int i = ; i< m; i++)
if(obstacleGrid[i][] == ) grid[i][] = ;
else break; for(int i = ; i< m; i++)
for(int j = ; j< n; j++)
if(obstacleGrid[i][j] == )
grid[i][j] = grid[i-][j] + grid[i][j-]; return grid[m-][n-];
}
};

LeetCode_Unique Paths II的更多相关文章

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

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

  2. 62. Unique Paths && 63 Unique Paths II

    https://leetcode.com/problems/unique-paths/ 这道题,不利用动态规划基本上规模变大会运行超时,下面自己写得这段代码,直接暴力破解,只能应付小规模的情形,当23 ...

  3. 【leetcode】Unique Paths II

    Unique Paths II Total Accepted: 22828 Total Submissions: 81414My Submissions Follow up for "Uni ...

  4. 61. Unique Paths && Unique Paths II

    Unique Paths A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagra ...

  5. LeetCode: Unique Paths II 解题报告

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

  6. 【LeetCode练习题】Unique Paths II

    Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are added to ...

  7. LeetCode之“动态规划”:Minimum Path Sum && Unique Paths && Unique Paths II

    之所以将这三道题放在一起,是因为这三道题非常类似. 1. Minimum Path Sum 题目链接 题目要求: Given a m x n grid filled with non-negative ...

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

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

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

随机推荐

  1. 【HDOJ】1104 Remainder

    bfs. #include <cstdio> #include <cstring> #include <cstdlib> #include <queue> ...

  2. google开源的C++性能分析工具 - gperftools

    gperftools是Google提供的一套工具,其中的一个功能是CPU profiler,用于分析程序性能,找到程序的性能瓶颈. 安装 gperftools:http://code.google.c ...

  3. 重写boost内存池

    最近在写游戏服务器网络模块的时候,需要用到内存池.大量玩家通过tcp连接到服务器,通过大量的消息包与服务器进行交互.因此要给每个tcp分配收发两块缓冲区.那么这缓冲区多大呢?通常游戏操作的消息包都很小 ...

  4. lesson3.1:java公平锁和非公平锁及读写锁

    关于这四种锁的各自情况,网上有很多文章做了介绍,本不想单独开章节介绍,本章只介绍这四种锁的一些源码特点及注意事项. demo 源码:https://github.com/mantuliu/javaAd ...

  5. dialog中的button动态设置为disable[转]

    我们再写dialog的时候,会时常有这样一种需求,希望通过某些条件将dialog的button设置为disable的. 基本的命令就是将“确定”这个button设置为disable(false). 如 ...

  6. IE6下的怪异解析知识点补充

    转载请注明出处:HTMl5自由者      

  7. Intel 被 ARM 逼急了

    英特尔最近推出基于Silvermont架构Bay Trail系列处理器,相对前一代Bonnell架构的最突出的改进就是支持乱序执行 silvermon架构的处理器将出现在pc,平板等: List of ...

  8. 中国大推力矢量发动机WS15 跨入 世界先进水平!

    "太行"WS-15让俄闭嘴令美叹服 歼20试飞向世界证明,中国军工世界一流,并有望与美英法争夺新一代航空发动机桂冠.笔者请教解放军专家证实:中国四代机所配套的两台18吨推力的WS- ...

  9. 金典 SQL笔记(4)

    由于在本地笔记上写的.CSDN markdown编辑器仅仅支持.md格式导入, 图片没办法直接导进去.写的多了懒的一张一张图片切图上传; 直接整个文章切成图片上传上去了. watermark/2/te ...

  10. hdu 3395

    KM裸题 每个鱼都认为自己是雄性,而且会攻击它认为是雌性的鱼,每个鱼只能被攻击一次,被攻击后会产卵(个数是给的两条鱼的值的异或运算) #include<string.h> #include ...