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 ...
随机推荐
- E - Redundant Paths - poj 3177(缩点求叶子节点)
题意:给一个图,想让每两个点之间都有两条路相连,不过特殊的是相同的两点之间多次相连被认为是一条边,现在求最少还需要添加几条边才能做到 分析:手欠没看清楚是相同的边只能相连一次,需要去重边,缩点后求出来 ...
- thinkphp+datatables+ajax 大量数据服务器端查询
今天一白天全耗在这个问题上了,知乎2小时除外... 现在19:28分,记下来以备后查. 问题描述:从后台数据库查询人员信息,1w多条,使用一个好看的基于bootstrap的模板 Bootstrap-A ...
- JS-Date日期内置对象
1.基本用法 <script> var date = new Date(); document.write(date+"<br/>");//获取具体时间 d ...
- (转)在SAE使用Apple Push Notification Service服务开发iOS应用, 实现消息推送
在SAE使用Apple Push Notification Service服务开发iOS应用, 实现消息推送 From: http://saeapns.sinaapp.com/doc.html 1,在 ...
- Jmeter接口测试-badboy录制脚本(二)
1.脚本录制,采用badboy进行录制,操作步骤很简单 2.badboy简介: Badboy是一款免费WEB自动化测试工具. 官方下载地址:http://www.badboy.com.au badbo ...
- 设置应用中出现NFC服务,去掉
还可以在 里面修改
- 宙斯是一个完整的Hadoop的作业平台[转]
https://github.com/alibaba/zeus 宙斯(zeus)是什么 宙斯是一个完整的Hadoop的作业平台从Hadoop任务的调试运行到生产任务的周期调度 宙斯支持任务的整个生命周 ...
- [置顶] .net技术类面试、笔试题汇总1
1.简述 private. protected. public. internal 修饰符的访问权限. private : 私有成员, 在类的内部才可以访问. protected : 保护成员,该类内 ...
- sgu Flow construction
Flow construction 题目: 给出N个节点M条水管,要求在满足上下界的情况下.满足起点最小的流量. 算法: 这是最小流????不知道.仅仅知道用求解上下界最大流的方法就过了. 做这题收获 ...
- DFBle.swift
//// DFBle.swift// DFBle//// Created by LeeYaping on 15/9/2.// Copyright (c) 2015年 lisper. All r ...