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

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. HDU1412

    大水题.. 求集合的并 /* */ #include<algorithm> #include<iostream> #include<string.h> #inclu ...

  2. MySql不同版本安装

    1.win7 64位下如何安装配置mysql-5.7.4-m14-winx64  1. mysql-5.7.4-m14-winx64.zip下载 2.解压到D:/mysql.(路径自己指定) 3.在D ...

  3. http://jingyan.baidu.com/article/e4511cf33479812b855eaf67.html

    http://jingyan.baidu.com/article/e4511cf33479812b855eaf67.html

  4. 186. Reverse Words in a String II

    题目: Given an input string, reverse the string word by word. A word is defined as a sequence of non-s ...

  5. 123. Best Time to Buy and Sell Stock III

    题目: Say you have an array for which the ith element is the price of a given stock on day i. Design a ...

  6. Scrapy在win7 32位的安装及依赖包

    Scrapy,一个网络爬虫的框架,首先第一步肯定是安装. 参考网上的文章. 安装过程中需要用到pip工具,请自行安装. 1.安装python 这个是必须的,既然都用到scrapy了,肯定已经安装了py ...

  7. 1523. K-inversions(K逆序对)

    1523 这题应该说有一些DP的思想吧 dp[i][j]表示以i为结尾第j个数的个数 k单调下降 直接求的话肯定超时 然后用树状数组来进行维护 求k-1次树状数组 #include <iostr ...

  8. poj 2506 Tiling(递推 大数)

    题目:http://poj.org/problem?id=2506 题解:f[n]=f[n-2]*2+f[n-1],主要是大数的相加; 以前做过了的 #include<stdio.h> # ...

  9. PHP内置的Web Server的使用

    自PHP5.4之后 PHP内置了一个Web 服务器. 让我们来看看php Web Server的简单使用: 启动php Web Server php -S localhost:8080 通过 php ...

  10. WinCE发展史

    Windows CE概述 WindowsCE是微软公司嵌入式.移动计算平台的基础,它是一个开放的.可升级的32位嵌入式操作系统,是基于掌上型电脑类的电子设备操作系统,它是精简的Windows 95,W ...