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 ...
随机推荐
- hdu 3631
最短路 执行一遍 Floyd算法 比赛的时候没有想到, 用了优化的Dijkstra 超时到死 #include <cstdio> #include <cstring> ...
- Firefly Http通信简单介绍
原地址:http://www.9miao.com/question-15-54042.html 首先创建firefly工程,firefly-admin.py createproject httptes ...
- static函数与普通函数
转自http://blog.163.com/sunshine_linting/blog/static/44893323201191294825184/ 全局变量(外部变量)的说明之前再冠以static ...
- Side-by-side assembly
Side-by-side technology is a standard for executable files in Windows 98 Second Edition, Windows 200 ...
- live555源码研究(一)------live555MediaServer的启动过程和基本类图
live555MediaServer.cpp就是live555服务器启动的过程. 一.启动过程 1,构造运行环境,运行环境包括了TaskScheduler 2,构造鉴权数据,也就是登陆的用户名和密码等 ...
- Eclipse中查看Android模拟器SD卡目录
· 有时候用到Android模拟器来模拟SD卡相关操作,在Eclipse中可以直接查看SD卡目录: 首先,新建模拟器的时候要创建SD卡,存储的大小根据需要创建: 启动模拟器,在Eclipse中打开视图 ...
- Fisher's exact test( 费希尔精确检验)
Fisher's exact test[1][2][3] is a statistical significance test used in the analysis ofcontingency t ...
- Java 简单的加密解密算法
package cn.std.util; import java.nio.charset.Charset; public class DeEnCode { private static final S ...
- poj 3083 Children of the Candy Corn(DFS+BFS)
做了1天,总是各种错误,很无语 最后还是参考大神的方法 题目:http://poj.org/problem?id=3083 题意:从s到e找分别按照左侧优先和右侧优先的最短路径,和实际的最短路径 DF ...
- Unity3D中使用3DMAX建模规范
1.将3Dmax中的单位制设置为厘米. 如果使用3DMax来建模的话,可将3DMax的系统默认单位改成厘米 〉Customize - Units Setup - Metric - Display U ...