1. class Solution {
  2. public:
  3. int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
  4. if(obstacleGrid.size()== || obstacleGrid[].size()==) return ;
  5. int m = obstacleGrid.size(), n = obstacleGrid[].size();
  6. if(obstacleGrid[m-][n-]==) return ;
  7.  
  8. vector<vector<int> > dp(m);
  9. for(int i=;i<dp.size();++i) dp[i].resize(n);
  10. for(int i=;i<dp.size();++i){
  11. for(int j=;j<dp[i].size();++j) dp[i][j]=;
  12. }
  13.  
  14. dp[][] = (obstacleGrid[][]==) ? : ;
  15. for(int i=;i<dp.size();++i){
  16. if(dp[i-][] && !obstacleGrid[i][]) dp[i][] = ;
  17. }
  18. for(int j=;j<dp[].size();++j){
  19. if(dp[][j-] && !obstacleGrid[][j]) dp[][j] = ;
  20. }
  21. for(int i=;i<dp.size();++i){
  22. for(int j=;j<dp[i].size();++j){
  23. if(i>= && !obstacleGrid[i-][j]) dp[i][j] += dp[i-][j];
  24. if(j>= && !obstacleGrid[i][j-]) dp[i][j] += dp[i][j-];
  25. }
  26. }
  27.  
  28. return dp[m-][n-];
  29. }
  30. };

leetcode@ [62/63] Unique Paths II的更多相关文章

  1. 【LeetCode】63. Unique Paths II

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

  2. 【一天一道LeetCode】#63. Unique Paths II

    一天一道LeetCode (一)题目 Follow up for "Unique Paths": Now consider if some obstacles are added ...

  3. 【LeetCode】63. Unique Paths II 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/unique-pa ...

  4. LeetCode OJ 63. Unique Paths II

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

  5. [leetcode DP]63. Unique Paths II

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

  6. &lt;LeetCode OJ&gt; 62. / 63. Unique Paths(I / II)

    62. Unique Paths My Submissions Question Total Accepted: 75227 Total Submissions: 214539 Difficulty: ...

  7. leetcode 62. Unique Paths 、63. Unique Paths II

    62. Unique Paths class Solution { public: int uniquePaths(int m, int n) { || n <= ) ; vector<v ...

  8. 【leetcode】62.63 Unique Paths

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

  9. 62. Unique Paths && 63 Unique Paths II

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

随机推荐

  1. 使用程序获取整型数据和浮点型数据在内存中的表示---gyy整理

    使用程序获取整型数据和浮点型数据在内存中的表示. C++中整型(int).短整型(short int).单精度浮点数(float).双精度浮点数(double)在内存中所占字节数不同,因此取值范围也不 ...

  2. 第二个C语言代码

    有问题,还没找出哪里出错了       输入一串字符,问号结束 统计1~9各出现的次数 ******************************************************** ...

  3. 性能优化工具 MVC Mini Profiler

    性能优化工具 MVC Mini Profiler   MVC MiniProfiler是Stack Overflow团队设计的一款对ASP.NET MVC.WebForm 以及WCF 的性能分析的小程 ...

  4. GCC警告选项例解

    程序员是追求完美的一族,即使是一般的程序员大多也都不想看到自己的程序中有甚至那么一点点的瑕疵.遇到任意一条编译器警告都坚决不放过.有人会说:我们可以使用比编译器更加严格的静态代码检查工具,如splin ...

  5. python set type 集合类型的数据介绍 (set frozenset)

      python支持数学中的集合概念,如:通过in,not in 可以检查某元素是否在,不在集合中. python有两种集合类型,set(可以变的,不能哈希,不能用作字典的key),frozenset ...

  6. PC寄存器的真实状态

    因为预取指令的关系,PC寄存器永远比当前的寄存器多两个指令,ARM模式为大8,Thumb模式为大2,这针对的是32bit的ARMv7的指令集 In ARM state, the value of th ...

  7. Android中Input型输入设备驱动原理分析<一>

    话说Android中Event输入设备驱动原理分析还不如说Linux输入子系统呢,反正这个是没变的,在android的底层开发中对于Linux的基本驱动程序设计还是没变的,当然Android底层机制也 ...

  8. 【HDOJ】2385 Stock

    水题,逆向做+优先级队列. /* 2385 */ #include <iostream> #include <sstream> #include <string> ...

  9. Android开发之在子线程中使用Toast

    在子线程中使用Toast的时候,出现Force close. 错误提示:Can't create handler inside thread that has not called Looper.pr ...

  10. Codeforces 374A - Inna and Pink Pony

    原题地址:http://codeforces.com/contest/374/problem/A 好久没写题目总结了,最近状态十分不好,无论是写程序还是写作业还是精神面貌……NOIP挂了之后总觉得缺乏 ...