leetcode@ [62/63] Unique Paths II
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的更多相关文章
- 【LeetCode】63. Unique Paths II
Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are added to ...
- 【一天一道LeetCode】#63. Unique Paths II
一天一道LeetCode (一)题目 Follow up for "Unique Paths": Now consider if some obstacles are added ...
- 【LeetCode】63. Unique Paths II 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/unique-pa ...
- LeetCode OJ 63. Unique Paths II
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 OJ> 62. / 63. Unique Paths(I / II)
62. Unique Paths My Submissions Question Total Accepted: 75227 Total Submissions: 214539 Difficulty: ...
- leetcode 62. Unique Paths 、63. Unique Paths II
62. Unique Paths class Solution { public: int uniquePaths(int m, int n) { || n <= ) ; vector<v ...
- 【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 ...
- 62. Unique Paths && 63 Unique Paths II
https://leetcode.com/problems/unique-paths/ 这道题,不利用动态规划基本上规模变大会运行超时,下面自己写得这段代码,直接暴力破解,只能应付小规模的情形,当23 ...
随机推荐
- sort-based shuffle的核心:org.apache.spark.util.collection.ExternalSorter
依据Spark 1.4版 在哪里会用到它 ExternalSorter是Spark的sort形式的shuffle实现的关键.SortShuffleWriter使用它,把RDD分区中的数据写入文件. o ...
- Ubuntu环境下手动配置Java环境
/×××××××××××××××××××××××××××××××××××××××××/ Author:xxx0624 HomePage:http://www.cnblogs.com/xxx0624/ ...
- tomcat 禁止某些文件(夹)的访问
tomcat 禁止某些文件(夹)的访问 <!-- 不允许访问的文件以及文件夹 --> <security-constraint> <display-name>Tom ...
- MSSQLServer基础05(联合查询,连接查询)
联合结果集union(集合运算符) 集合运算符是对两个集合操作的,两个集合必须具有相同的列数,列具有相同的数据类型(至少能隐式转换的),最终输出的集合的列名由第一个集合的列名来确定.(可以用来连接多个 ...
- adb开启不了解决方案
原文地址: adb开启不了解决方案 - vaecer - 博客频道 - CSDN.NET http://blog.csdn.net/vaecer/article/details/45894643 ...
- ArcGIS学习记录—ArcGIS ArcMap编辑状态中线打断的问题
摘要:在处理数据时,我们经常会遇到线打断的问题,比如需要指定在线上某处打断线,或者新建网络数据集时需要在线的交点处打段线等等.现将桌面版中我所遇到的线打断的工具总结如下: 在ArcGIS矢量处理数据时 ...
- POJ2253——Frogger(Floyd变形)
Frogger DescriptionFreddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fi ...
- SQL盲注修订建议
一般有多种减轻威胁的技巧: [1] 策略:库或框架 使用不允许此弱点出现的经过审核的库或框架,或提供更容易避免此弱点的构造. [2] 策略:参数化 如果可用,使用自动实施数据和代码之间的分离的结构化机 ...
- Android EditText中插入图片并响应点击事件
EditText中插入图片基本就是两种方法: ,通过Html.fromHtml(..)来实现 [mw_shl_code=java,true]eText.append(Html.fromHtml(&qu ...
- SharePoint2013切换帐户登录菜单
SharePoint2013帐户姓名显示的地方没有切换帐户的菜单,这个功能对于终端用户是可有可无的,但对于sharepoint管理员或sharepoint开发人员来讲,却是一个很重要的菜单,由于经常要 ...