LeetCode 063 Unique Paths II
来源:互联网 发布:js offsetwidth 属性 编辑:程序博客网 时间:2024/06/03 21:16
题目同上一题,但是在棋盘的某些格子加了障碍物,不能经过这些格子。
同使用递推法,如果当前格子为障碍格,就把到达当前格的路径数置零。
代码:
int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) { int m = obstacleGrid.size(); int n = obstacleGrid.front().size(); int f[101][101] = {0}; f[0][0] = 1 - obstacleGrid[0][0]; for(int i = 0 ; i < m ; i++) for(int j = 0 ; j < n ; j++) { if(i != 0 && j == 0) f[i][j] = obstacleGrid[i][j] ? 0 : f[i - 1][j]; else if(i == 0 && j != 0) f[i][j] = obstacleGrid[i][j] ? 0 : f[i][j - 1]; else if(i != 0 && j != 0) f[i][j] = obstacleGrid[i][j] ? 0 : (f[i][j - 1] + f[i - 1][j]); } return f[m-1][n-1]; }
0 0
- LeetCode 063 Unique Paths II
- LeetCode 063 Unique Paths II
- LeetCode 063 Unique Paths II
- leetcode 063 Unique Paths II
- LeetCode 063 Unique Paths II
- LeetCode: Unique Paths II
- [Leetcode] Unique Paths II
- LeetCode : Unique Paths II
- [LeetCode] Unique Paths II
- [LeetCode]Unique Paths II
- [leetcode]Unique Paths II
- LeetCode-Unique Paths II
- [leetcode] Unique Paths II
- LeetCode - Unique Paths II
- LeetCode:Unique Paths II
- 【LeetCode】Unique Paths II
- leetcode Unique Paths II
- LeetCode Unique Paths II
- 论 Function和 Object的辩证关系
- 奇妙的 10^n + 1
- EditText 多行显示同时支持软键盘监听
- 飞机游戏增加BOSS功能
- Spring MVC 流程图
- LeetCode 063 Unique Paths II
- 安装虚拟机
- CheckedTextView 复选框左显示
- 常见类的基本使用
- UI坐标系转换
- Kinect开发教程——OpenNI的安装与开发环境的配置
- 教你ios10怎么降级到ios9.3.2
- iOS--错误集锦--load the "xx" nib but the view outlet was not set.
- MAC地址