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的更多相关文章

  1. LEETCODE —— Unique Paths II [动态规划 Dynamic Programming]

    唯一路径问题II Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are ...

  2. 62. Unique Paths && 63 Unique Paths II

    https://leetcode.com/problems/unique-paths/ 这道题,不利用动态规划基本上规模变大会运行超时,下面自己写得这段代码,直接暴力破解,只能应付小规模的情形,当23 ...

  3. 【leetcode】Unique Paths II

    Unique Paths II Total Accepted: 22828 Total Submissions: 81414My Submissions Follow up for "Uni ...

  4. 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 ...

  5. LeetCode: Unique Paths II 解题报告

    Unique Paths II Total Accepted: 31019 Total Submissions: 110866My Submissions Question Solution  Fol ...

  6. 【LeetCode练习题】Unique Paths II

    Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are added to ...

  7. LeetCode之“动态规划”:Minimum Path Sum && Unique Paths && Unique Paths II

    之所以将这三道题放在一起,是因为这三道题非常类似. 1. Minimum Path Sum 题目链接 题目要求: Given a m x n grid filled with non-negative ...

  8. [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 ...

  9. LEETCODE —— Unique Paths II [Dynamic Programming]

    唯一路径问题II Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are ...

随机推荐

  1. HDU4605---Magic Ball Game(主席树 好题)

    题意:一颗二叉树,任意节点要么有两个孩子要么没孩子. 然后有一个球,从结点1开始往子孙结点走. 每碰到一个结点,有三种情况 如果此球重量等于该结点重量,球就停下了 如果此球重量小于该结点重量,则分别往 ...

  2. FZU 11月月赛D题:双向搜索+二分

    /* 双向搜索感觉是个不错的技巧啊 */ 题目大意: 有n的物品(n<=30),平均(两个人得到的物品差不能大于1)分给两个人,每个物品在每个人心目中的价值分别为(vi,wi) 问两人心目中的价 ...

  3. Power(int base, int exponent) 函数实现

    这个是个高效的算法,时间复杂度为 O(logn) 原理: a的n次方: #include<iostream> #include<cmath> using namespace s ...

  4. iOS BMOB-登录注册手机验证码、邮箱验证

    1.下载BmobSDK 2.把里面的BmobSDK.framework拖到你的工程里面的工具文件夹内. 3.导入类库 CoreLocation.framework.Security.framework ...

  5. 【小程序开发】微信小程序开发中遇到的那些坑...

    第一坑: 设置了三个tabBar,却默认显示第二个,不能展示我的第一个[首页]. "list": [{ "pagePath":"page/KTGJ/i ...

  6. VC用OLE方式读写Excel

    前几天要做一个项目,需要读取Excel中的数据.从网上查资料发现,主要是有两种方式.一是把Excel表当成数据库使用ODBC读写,这样操作起来就跟操作Access数据库似的.但这种方式效率比较低.另一 ...

  7. Codeforces 328A-IQ Test(数列)

    A. IQ Test time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  8. Mysql数据库里面的String类型依照数字来排序以及按时间排序的sql语句

    今天做项目的时候,遇到个小小的问题,在数据库中查询的时候,要用String类型的ID进行一下排序!(注:ID字段为 varchar 类型) 解决的方法: 如: SELECT * FROM  Stude ...

  9. 关于CCRect

    一直有一个误区,因为之前处理的公司引擎是屏幕坐标系 导致觉得CCRect的坐标起始值(x,y),习惯性的认为就是左上角的点. 但是,真正的x,y值,是跟x轴与y轴相对应的.

  10. 自定义控件 进度条 ProgressBar-2

    使用 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:bqt ...