Leetcode: UniquePath II
Description:
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.
分析:这道题目跟之前的UniquePath基本都是一样的,只是在格子中加了障碍物。基本思路是深搜+备忘录
但是不知道为什么会超时。。基本就跟答案一样,以后分析
int pathrec[][]={};
class Solution {
public:
int findpath(vector<vector<int> >& grid, int m, int n,int x,int y)
{
if(grid[m][n]==)
return ;
if(pathrec[m][n]!=)
return pathrec[m][n];
int pathnum = ;
if(m==x- && n==y-)
{
pathrec[m][n] = ;
return ;
}
if(m+<x) pathnum+= findpath(grid,m+,n,x,y);
if(n+<y) pathnum+= findpath(grid,m,n+,x,y);
pathrec[m][n] = pathnum;
return pathnum;
}
int uniquePathsWithObstacles(vector<vector<int> > &obstacleGrid) {
if(obstacleGrid.empty() || obstacleGrid[].empty()) return ;
int x = obstacleGrid.size(); int y= obstacleGrid[].size();
memset(pathrec,,sizeof(pathrec));
int pathnum = findpath(obstacleGrid,,,x,y);
return pathnum;
}
};
Leetcode: UniquePath II的更多相关文章
- leetcode Permutations II 无重全排列
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4051169.html 题目链接:leetcode Permutations II 无重全排 ...
- [LeetCode] Permutations II 全排列之二
Given a collection of numbers that might contain duplicates, return all possible unique permutations ...
- LeetCode Permutaions II
LeetCode解题之Permutaions II 原题 输出一个有反复数字的数组的全排列. 注意点: 反复数字的可能导致反复的排列 样例: 输入: nums = [1, 2, 1] 输出: [[1, ...
- [LeetCode] 4Sum II 四数之和之二
Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such t ...
- [LeetCode] H-Index II 求H指数之二
Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize ...
- [LeetCode] Subsets II 子集合之二
Given a collection of integers that might contain duplicates, S, return all possible subsets. Note: ...
- [LeetCode] N-Queens II N皇后问题之二
Follow up for N-Queens problem. Now, instead outputting board configurations, return the total numbe ...
- LeetCode H-Index II
原题链接在这里:https://leetcode.com/problems/h-index-ii/ 题目: Follow up for H-Index: What if the citations a ...
- LeetCode Subsets II (DFS)
题意: 给一个集合,有n个可能相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: 看这个就差不多了.LEETCODE SUBSETS (DFS) class Solution { publ ...
随机推荐
- Android物业动画研究(Property Animation)彻底解决具体解释
前p=1959">Android物业动画研究(Property Animation)全然解析具体解释上已经基本展示了属性动画的核心使用方法: ObjectAnimator实现动画 ...
- IE打印的参数配置说明
IE自动给我们在页眉和页脚处加上了这些不必要的打印信息.如果我们不想要任何页眉和页脚的话,直接删除它们就行了.:-)大部分时候我都是这样做的.但如果你想自定义页眉和页脚的时候,该怎么做呢?上面的那些“ ...
- linux旁边flv注射MetaData工具
1,yamdi 官方网站:http://yamdi.sourceforge.net/ 下载链接:http://sourceforge.net/projects/ya ...
- Android开发之控制Toast的开启与关闭
开发这个程序之前先解释一下,为什么Toast信息提示框在显示一定时间后会自己主动消失?由于在Android系统中有一个Toast队列,系统会依次从这个队列中取出一个Toast,并显示它.在显示了指定时 ...
- windows编ffmpeg2.2.4和插件h265
0.前言 据说新出来了h265的视频,在迅雷看看上面看到的.网上查看了一下简单介绍,貌似h265的视频比h264的视频压缩率要高.并且能做4K的视频. 同一时候看到网上有人试过ffmpeg在编译的时候 ...
- 一个JavaWeb项目开发总结
一.学会如何读一个JavaWeb项目源代码 步骤:表结构->web.xml->mvc->db->spring ioc->log->代码 先了解项目数据库的表结构,这 ...
- MVC使用Bootstrap
ASP.NET MVC使用Bootstrap系列(5)——创建ASP.NET MVC Bootstrap Helpers 摘要: 序言ASP.NET MVC允许开发者创建自定义的HTML Helper ...
- Sample Page
This is an example page. It's different from a blog post because it will stay in one place and will ...
- VS2015 Apache Cordova
VS2015 Apache Cordova第一个Android和IOS应用 前言 本人个人博客原文链接地址为http://aehyok.com/Blog/Detail/75.html. http: ...
- openwrt固件支持3G和4G上网卡
http://wiki.openwrt.org/doc/howtobuild/wireless-router-with-a-3g-dongle Building image with support ...