Unique Paths II
来源:互联网 发布:网站域名是什么 编辑:程序博客网 时间:2024/06/08 09:50
二维动态规划。
class Solution {public: int map[101][101]; int uniquePathsWithObstacles(vector<vector<int> > &obstacleGrid) { for (int i = 0; i < 101; ++i) for (int j = 0; j < 101; ++j) map[i][j] = -1; if (obstacleGrid.size() == 0) return 0; if (obstacleGrid[0].size() == 0) return 0; return helper(obstacleGrid, 0, 0, obstacleGrid.size() - 1, obstacleGrid[0].size() - 1); } int helper(vector<vector<int>> &obstacleGrid, int i, int j, int m, int n) { if (i == m && j == n && obstacleGrid[i][j] != 1) { map[i][j] = 1; return map[i][j]; } if (i > m || j > n || obstacleGrid[i][j] == 1) return 0; if (map[i][j] != -1) return map[i][j]; map[i][j] = helper(obstacleGrid, i + 1, j, m, n) + helper(obstacleGrid, i, j + 1, m, n); return map[i][j]; }};
http://oj.leetcode.com/problems/unique-paths-ii/
0 0
- Unique Paths & Unique Paths II
- Unique Paths &&Unique Paths II
- Unique Paths & Unique Paths II
- Unique Paths & Unique Paths II
- LeetCode: Unique Paths II
- [Leetcode] Unique Paths II
- LeetCode : Unique Paths II
- Unique Paths II
- [LeetCode] Unique Paths II
- unique paths II
- Unique Paths II
- [LeetCode]Unique Paths II
- Unique Paths II
- Unique Paths II
- Unique Paths II
- Unique Paths II
- [leetcode]Unique Paths II
- Unique Paths II
- AJAX Note
- grep之字符串搜索算法Boyer-Moore由浅入深(比KMP快3-5倍)
- Android广告平台介绍
- Struts1.x note
- SIGSEGV时自动打印栈帧(2014.02.28 更新)
- Unique Paths II
- 弹出无边框页面,(将页面以div的形式弹出)
- Struts2.x note
- Spring note
- EJB note
- Android SDCard Mount 流程分析(一)
- WebService note
- Android SDCard Mount 流程分析(二)
- 各种开源协议License明细