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.

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

63. Unique Paths II (Graph; DP)的更多相关文章

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

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

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

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

  3. 【LeetCode】63. Unique Paths II

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

  4. 63. Unique Paths II(中等, 能独立做出来的DP类第二个题^^)

    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. [LeetCode] 63. Unique Paths II 不同的路径之二

    A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...

  7. 63. Unique Paths II

    题目: Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. H ...

  8. LeetCode OJ 63. Unique Paths II

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

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

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

随机推荐

  1. SharePoint 2013的100个新功能之搜索(一)

    一:新的搜索架构 SharePoint 2013中将最好的两个搜索引擎"SharePoint搜索"和"SharePoint FAST搜索服务"整合到了一个搜索引 ...

  2. linux下部署tomcat服务器之安装jdk

    如果一开始安装过jdk的可以卸载 rpm -qa | grep java rpm -e --nodeps java-1.6.0-openjdk-1.6.0.0-1.50.1.11.5.el6_3.x8 ...

  3. PostgreSQL设置事务隔离级别实验

    apple=# begin; BEGIN apple=# set transaction ISOLATION LEVEL read committed ; SET apple=# select * f ...

  4. angularjs指令中的require赋值含义

    前缀 寻找路劲 没有找到控制器是否抛错? 例如 Link函数中第四个参数 (no prefix) 当前指令的DOM 抛错 tabset 找到的Controller对象 ? 当前指令的DOM 不抛错 ? ...

  5. 解决HTML加载时,外部js文件引用较多,影响页面打开速度问题

    解决HTML加载时,外部js文件引用较多,影响页面打开速度问题   通常HTML文件在浏览器中加载时,浏览器都会按照<script>元素在页面中出现的先后顺序,对它们依次加载,一旦加载的j ...

  6. PyAlgoTrade Hello World 第一个程序(一)

    本教程的目标是快速介绍PyAlgoTrade.PyAlgoTrade的目标是帮助您实现股票交易策略.假设您有一个交易策略的想法,并且您希望使用历史数据进行评估,并查看其行为方式,那么PyAlgoTra ...

  7. 伴随我整十个年头的校内网,现名 人人网, 是不是要shut down 了

    如题: 每天我都习惯性的登录人人网,虽然现在基本上已经看不到曾经的同学上线了,不过我还是有事没事的往上面post 一些出行的照片,没事无聊的时候上这个网上看看自己曾经的照片,虽然已经无人在线,但是自己 ...

  8. zepto 自定义build

    为啥要自定义build? 一般来说我们都会直接在官网下,但它只包含默认几个的模块,对于移动开发,这些模块有些是需要的,有些则可以不用.所以我们可以根据自己的需要来定制. 下图为zepto包含的模块,其 ...

  9. test20181024 kun

    题意 分析 考场做法 任意状态只有两种决策,进栈或出栈. 由于元素互不相同,所以选择的关键在于栈顶元素是否在它和带插入元素组成的集合中是最大的. 用stack和set维护.时间复杂度\(O(n \lo ...

  10. 对ashx请求用Gzip,Deflated压缩

    //GZIP压缩 //查看请求头部 string acceptEncoding = context.Request.Headers["Accept-Encoding"].ToStr ...