LeetCode_Unique Paths II
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]
] he total number of unique paths is 2. Note: m and n will be at most 100.
同Unique Paths的DP类似。
class Solution {
public:
int uniquePathsWithObstacles(vector<vector<int> > &obstacleGrid) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int m = obstacleGrid.size();
int n = obstacleGrid[].size();
vector<vector<int>> grid(m, vector<int>(n,));
for(int i = ; i< n; i++)
if(obstacleGrid[][i] ==) grid[][i] = ;
else break;
for(int i = ; i< m; i++)
if(obstacleGrid[i][] == ) grid[i][] = ;
else break; for(int i = ; i< m; i++)
for(int j = ; j< n; j++)
if(obstacleGrid[i][j] == )
grid[i][j] = grid[i-][j] + grid[i][j-]; return grid[m-][n-];
}
};
LeetCode_Unique Paths II的更多相关文章
- LEETCODE —— Unique Paths II [动态规划 Dynamic Programming]
唯一路径问题II Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are ...
- 62. Unique Paths && 63 Unique Paths II
https://leetcode.com/problems/unique-paths/ 这道题,不利用动态规划基本上规模变大会运行超时,下面自己写得这段代码,直接暴力破解,只能应付小规模的情形,当23 ...
- 【leetcode】Unique Paths II
Unique Paths II Total Accepted: 22828 Total Submissions: 81414My Submissions Follow up for "Uni ...
- 61. Unique Paths && Unique Paths II
Unique Paths A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagra ...
- LeetCode: Unique Paths II 解题报告
Unique Paths II Total Accepted: 31019 Total Submissions: 110866My Submissions Question Solution Fol ...
- 【LeetCode练习题】Unique Paths II
Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are added to ...
- LeetCode之“动态规划”:Minimum Path Sum && Unique Paths && Unique Paths II
之所以将这三道题放在一起,是因为这三道题非常类似. 1. Minimum Path Sum 题目链接 题目要求: Given a m x n grid filled with non-negative ...
- [LeetCode] Unique Paths && Unique Paths II && Minimum Path Sum (动态规划之 Matrix DP )
Unique Paths https://oj.leetcode.com/problems/unique-paths/ A robot is located at the top-left corne ...
- LEETCODE —— Unique Paths II [Dynamic Programming]
唯一路径问题II Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are ...
随机推荐
- BZOJ3433: [Usaco2014 Jan]Recording the Moolympics
3433: [Usaco2014 Jan]Recording the Moolympics Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 55 So ...
- iOS 9之Shared Links Extension(Safari Extensibility)
金田 (github示例源码) 在之前的Blog中有介绍了关于Safari Extensibility的 Content Blocking部分,详情可以看这里 --- iOS 9之Safari广告拦截 ...
- 移动web app开发框架
文章地址:http://www.cnblogs.com/soulaz/p/5586787.html jQuery Mobile jQuery Mobile框架能够帮助你快速开发出支持多种移动设备的Mo ...
- hdu5136:组合计数、dp
题目大意: 求直径长度为N的无根二叉树的个数(同构的只算一种) 分析: 分析发现直径长度不好处理!因此考虑把问题转化一下: 假设要求直径为N的二叉树 (1) 若N为偶数,将树从直径中点的边断开,则分成 ...
- P - Atlantis - hdu1542(求面积)
题意:rt 求面积......不计算重复面积(废话..)hdu1255 的弱化版,应该先做这道题在做那道题的. ******************************************** ...
- hdu4111 Alice and Bob
Alice and Bob Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【C#基础】CSA控件编写秘籍
新建CSA控件 1.新建一个纯类,命名空间是: namespace SimPerfect.CSAControlLibrary.CSAControls 2.实现两个构造函数:无参和传Candy参数 pu ...
- CMA连续物理内存用户空间映射---(一)
背景: 在多媒体和图像处理等应用中,经经常使用到大块内存,尤其是硬件编解码.须要内核分配大块的物理连续内存. 这里希望通过把从内核分配的连续物理内存映射到用户空间.在用户空间经过处理,又能够入队到驱动 ...
- 解决Wamp 开启vhost localhost 提示 403 Forbbiden 的问题!
非常奇怪的一个问题.我曾经从来都没有这样过!訪问 http://localhost/ 提示 403 Forbbiden. 我之前的设置一直都是这种: httpd.conf <Directory ...
- 安装orcle10g oel5.6
一.安装OEL 5.6 二.安装VMware Tools 1) 选择菜单里的VM选项,里面有一个子选项是installVMware Tools,选择它. 2) 回到操作系统,将光驱挂载到/mnt ...