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 ...
随机推荐
- 保卫萝卜官方PC版——含绿色版 V1.0.6Beta
官方网站 | 安装版 | 绿色版
- Beta阶段第2周/共2周 Scrum立会报告+燃尽图 14
作业要求[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2411] 版本控制:https://git.coding.net/liuyy08 ...
- Ubuntu上交叉编译valgrind for Android 4.0.4的过程与注意事项
编译环境:Ubuntu x86_64(Linux root 2.6.32-45-generic #101-Ubuntu SMP Mon Dec 3 15:39:38 UTC 2012 x86_64 G ...
- Shell排序算法和合并排序算法
Shell排序(希尔排序)算法Shell排序严格来说基于插入排序的思想,其又称为希尔排序或者缩小增量排序. Shell排序的流程:1.将由n个元素的数组分成n/2个数字序列,第1个数据和第n/2+1个 ...
- redux中的compose源码分析
1. redux中compose用来组合各种中间件来实现链式调用,例子如下 compose( applyMiddleware, devTools, persistState, createStore ...
- 20155313 2016-2017-2 《Java程序设计》第六周学习总结
20155313 2016-2017-2 <Java程序设计>第六周学习总结 教材内容学习 第十章 输入/输出 10.1 InputStream与OutputStream 1.串流设计的概 ...
- maven打jar到私服
<dependency> <groupId>fakepath</groupId> <artifactId>wcs-java-sdk</artifa ...
- 基于 jmeter 和 shell 的接口性能自动化
jmeter+shell 1. 总体需求 由于性能测试中涉及的查询接口多,版本迭代频繁,版本更新后自动跑一轮查询业务的性能,可以及时发现一些开发修复bug触发的非预期的bug,利用晚上时间快速重测性能 ...
- mschart 使用心得和部署。
参考: http://www.cnblogs.com/suguoqiang/archive/2013/01/16/2862945.html 1.在统计时可能需要多条数据,需要整合数据源 Chart1. ...
- 解决 eclipse tomcat cannot create a server using the selected type
解决的方法 1.退出eclipse: 2.打开 [工程目录下]/.metadata/.plugins/org.eclipse.core.runtime/.settings目录: 3.删除org.ecl ...