博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Unique Paths II (dp题)
阅读量:7059 次
发布时间:2019-06-28

本文共 920 字,大约阅读时间需要 3 分钟。

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]]

The total number of unique paths is 2.

Note: m and n will be at most 100.

代码:

class Solution {public:    int uniquePathsWithObstacles(vector
> &obstacleGrid) { if(obstacleGrid.size()==0) return 0; int row=obstacleGrid.size(); int col=obstacleGrid[0].size(); int dp[100][100]; memset(dp,0,sizeof(dp)); bool rblockTag=false; bool cblockTag=false; if(obstacleGrid[0][0]==1||obstacleGrid[row-1][col-1]==1) return 0; for(int i=1;i

 

转载于:https://www.cnblogs.com/fightformylife/p/4229913.html

你可能感兴趣的文章
软件架构师的修炼之道
查看>>
[HDU 1372] Knight Moves
查看>>
java代码实现 金字塔(倒置)
查看>>
NOIP2015DAY2T2子串
查看>>
5种PHP创建数组的方式
查看>>
24. [Ext JS 4] 实战之Load Mask(加载遮罩)的显示与隐藏
查看>>
【C语言】07-基本语句和运算
查看>>
ajax异步获取提示框数据(鼠标悬浮事件)
查看>>
Android 内存使用hprof文件打开方法
查看>>
android入门一
查看>>
第16条:复合优先于继承
查看>>
[学习笔记]斯特林数
查看>>
oracle 修改表空间文件路径方法
查看>>
一张图理解RACSignal的Subscription过程
查看>>
objectLiteral.js
查看>>
Ext 面向对象程序设计 入门篇
查看>>
Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) 一夜回到小学生
查看>>
8皇后问题
查看>>
update comboBox
查看>>
包装类
查看>>