63. Unique Paths II (Graph; DP)
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)的更多相关文章
- leetcode 62. Unique Paths 、63. Unique Paths II
62. Unique Paths class Solution { public: int uniquePaths(int m, int n) { || n <= ) ; vector<v ...
- 62. Unique Paths && 63 Unique Paths II
https://leetcode.com/problems/unique-paths/ 这道题,不利用动态规划基本上规模变大会运行超时,下面自己写得这段代码,直接暴力破解,只能应付小规模的情形,当23 ...
- 【LeetCode】63. Unique Paths II
Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are added to ...
- 63. Unique Paths II(中等, 能独立做出来的DP类第二个题^^)
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- [leetcode DP]63. Unique Paths II
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- [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 ...
- 63. Unique Paths II
题目: Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. H ...
- LeetCode OJ 63. Unique Paths II
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- 【一天一道LeetCode】#63. Unique Paths II
一天一道LeetCode (一)题目 Follow up for "Unique Paths": Now consider if some obstacles are added ...
随机推荐
- 集成学习之Boosting —— Gradient Boosting实现
Gradient Boosting的一般算法流程 初始化: \(f_0(x) = \mathop{\arg\min}\limits_\gamma \sum\limits_{i=1}^N L(y_i, ...
- New Concept English Two 14 34
recently busy a lot ,just practices every morning. $课文32 购物变得很方便 324. People are not so hone ...
- 报错:Syntax error on tokens, delete these tokens
该问题意思是说:你有两个双引号或者你有没有关闭%>符号. 仔细检查代码 出现这样的错误一般是括号.中英文字符.中英文标点.代码前面的空格,尤其是复制粘贴的代码,去掉即可.
- 为什么有logistics函数
直观地看: 如果是softmax函数,我想有跟多的选择方向吧
- javaScript基础篇之数据类型
我主要学习廖雪峰老师官方网站的javaScript,所以很多都是出自于廖老师,请见谅.以下是廖老师的官方网站的地址:http://www.liaoxuefeng.com/wiki/0014344466 ...
- 【C#】Lambda
介绍 Lambda 表达式是一种可用于创建 委托 或 表达式目录树 类型的 匿名函数 . 通过使用 lambda 表达式,可以写入可作为参数传递或作为函数调用值返回的本地函数. Lambda 表达式对 ...
- DNS中NS和SOA区别
ns 授權很簡單… 假設你註冊的 domain 叫 abc.com ,而你有 ns1 與 ns2 兩台 server . 那,你必需從 .com 的權威伺服器授權給你,其設定或類似如此: $ORIGI ...
- zipkin对于dubbo的支持
对于Web端: 1. 需要在applicationContext的头部添加中添加prefix引用: xmlns:dubbo="http://code.alibabatech.com/sche ...
- BZOJ1252:序列终结者
浅谈\(splay\):https://www.cnblogs.com/AKMer/p/9979592.html 浅谈\(fhq\)_\(treap\):https://www.cnblogs.com ...
- 国产FPGA市场分析 该如何破局
2018年上半年对于中国半导体行业而言是多事之秋,发生了几件让国人深入思考的大事.我作为IC产业的逃兵,最近也在思考很多的问题,包括资本市场.集成电路行业和研究所的一些不成熟的想法. 2008年进入华 ...