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 ...
随机推荐
- highcharts 根据表格转化为不同的图表
<!doctype html> <html lang="zh"> <head> <meta http-equiv="Conten ...
- Django自定义用户认证系统Customizing authentication
扩展已有的用户模型Extending the existing User model 有两种方法来扩展默认的User Model而不用重写自己的模型.如果你不需要改变存储在数据库中的字段,而只是需要改 ...
- 动态规划晋级——HDU 3555 Bomb【数位DP详解】
转载请注明出处:http://blog.csdn.net/a1dark 分析:初学数位DP完全搞不懂.很多时候都是自己花大量时间去找规律.记得上次网络赛有道数位DP.硬是找规律给A了.那时候完全不知数 ...
- C#获取本地打印机列表,并将指定打印机设置为默认打印机
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...
- C#中种常用的计时器
1.System.Timers.Timer和System.Windows.Forms.Timer,它的最低识别为1/18s. 2.timeGetTime,他的最低识别能达到5ms. 3.System. ...
- JADE平台入门
相关介绍: JADE(Java Agent Development Framework,Java智能体开发框架) 用途: Java智能体开发框架 开发者: TILAB 主要功能: AMS.DF.ACC ...
- Java多线程性能优化
大家使用多线程无非是为了提高性能,但如果多线程使用不当,不但性能提升不明显,而且会使得资源消耗更大.下面列举一下可能会造成多线程性能问题的点: 死锁 过多串行化 过多锁竞争 切换上下文 内存同步 下面 ...
- poj2373
其实这道题不是很难,不难想到f[i]表示覆盖到[0,i]的最少喷头数 很明显是一个dp+单调队列的问题 但是细节问题比较多,首先是不能覆盖到[0,l]外面,所以长度为奇数不能被完全覆盖 还有一些区间[ ...
- 从算法入手讲解如何在SQL Server中实现最优最简
算法是计算机科学中一个重要的研究方向,是解决复杂问题的关键.在计算机世界中,算法无处不在.数据库是存储数据和执行大批量计算的场所,在数据库中使用一些简单的SQL命令,进行存储.查询.统计.以解决现实世 ...
- Socket编程(九)
此为网络编程的一个系列,后续会把内容补上.....