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

  1. leetcode Permutations II 无重全排列

    作者:jostree  转载请注明出处 http://www.cnblogs.com/jostree/p/4051169.html 题目链接:leetcode Permutations II 无重全排 ...

  2. [LeetCode] Permutations II 全排列之二

    Given a collection of numbers that might contain duplicates, return all possible unique permutations ...

  3. LeetCode Permutaions II

    LeetCode解题之Permutaions II 原题 输出一个有反复数字的数组的全排列. 注意点: 反复数字的可能导致反复的排列 样例: 输入: nums = [1, 2, 1] 输出: [[1, ...

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

  5. [LeetCode] H-Index II 求H指数之二

    Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize ...

  6. [LeetCode] Subsets II 子集合之二

    Given a collection of integers that might contain duplicates, S, return all possible subsets. Note: ...

  7. [LeetCode] N-Queens II N皇后问题之二

    Follow up for N-Queens problem. Now, instead outputting board configurations, return the total numbe ...

  8. LeetCode H-Index II

    原题链接在这里:https://leetcode.com/problems/h-index-ii/ 题目: Follow up for H-Index: What if the citations a ...

  9. LeetCode Subsets II (DFS)

    题意: 给一个集合,有n个可能相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: 看这个就差不多了.LEETCODE SUBSETS (DFS) class Solution { publ ...

随机推荐

  1. Alice&#39;s Chance

    id=1698" style="background-color:rgb(51,255,51)">主题链接 意甲冠军: 爱丽丝要拍电影.有n部电影,规定爱丽丝第i部 ...

  2. 阅读小记3(《C编程专家》)

    gets()不检查缓冲区空间.多余的字符将覆盖原来的栈的内容. fgets()的第二个參数说明最大读入的字符数. 假设这个參数值为n,那么fgets()就会读取最多n-1个字符或读完一个换行符为止.两 ...

  3. 读取上传的CSV为DataTable

    csv导入文件会把每列的数据用英文逗号分割开来,如果遇到某列中包含英文逗号,则会把该列用英文双引号进行包装. 如果csv文件中某列的数据本身包含英文逗号,应该使用读取字符串的方式进行解析数据,如csv ...

  4. Android 阅读Manifest在文件Application 在与其他节点meta-data定义自己的数据

    介绍 Android提供meta-date使用键值在实现自己的自定义配置的形式. 通常用作信道标识.它可以用在<application>,<activity>,<acti ...

  5. cralwer_爬虫代理中心的简要设计

    代理中心: 简单讲: 精细化控制限制资源的使用,保证有限资源的充分利用及有效性.支持动态增减,实时更新. 需求 rest api提供请求输入与输出 客户端使用代理心跳接收,用于更新代理的使用次数,被占 ...

  6. ThinkPHP 3.2 开放 cache注缓存,过滤非法字符

    打开缓存配置文件 /Application/Common/conf/cache.php源代码如下面: <?php return array( //'配置项'=>'配置值' 'LAYOUT_ ...

  7. .net mvc mssql easyui treegrid

    效果图 数据图   可以看到 这里是根据 MenuNo 来 分级别的,支持 无限极,第一级是 01 ,第二级就是 01XX ,第三级 就是 01XXOO.类似 id.pid ,Ztree 里面 也是这 ...

  8. 网站静态化处理—web前端优化—下【终篇】(13)

    网站静态化处理—web前端优化—下[终篇](13) 本篇继续web前端优化的讨论,开始我先讲个我所知道的一个故事,有家大型的企业顺应时代发展的潮流开始投身于互联网行业了,它们为此专门设立了一个事业部, ...

  9. 使用微软 URL Rewrite Module 开启IIS伪静态

    原文 使用微软 URL Rewrite Module 开启IIS伪静态 在IIS5和IIS6时代,我们使用URL REWRITING可实现URL重写,使得WEB程序实现伪静态,但默认情况下只能实现.A ...

  10. oracle存储过程+游标处理select数据

    create or replace PROCEDURE UPDATE_RECORDCODE is cursor location_data is select * from location wher ...