LeetCode 95. Unique Paths II
2017-05-05 11:12
309 查看
class Solution { public: int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) { int row = obstacleGrid.size(); int column = obstacleGrid[0].size(); cout<<row<<endl; cout<<column<<endl; int dp[100][100] = { 0 }; int temp; for (int i = 0; i < row; i++){ if (obstacleGrid[i][0] != 1){ dp[i][0] = 1; cout << "dp [%d] "<<i<<dp[i][0] << endl; temp = i+1; } else{ break; } } for (int j = temp; j<row; j++){ dp[j][0] = 0; } for (int k = 0; k < column; k++){ if (obstacleGrid[0][k] != 1){ dp[0][k] = 1; temp = k+1; } else{ break; } } for (int l = temp; l<column; l++){ dp[0][l] = 0; } int res; for (int m = 1; m < row; m++){ for (int n = 1; n < column; n++){ if (obstacleGrid[m] != 1){ dp[m] = dp[m - 1] + dp[m][n - 1]; } else{ dp[m] = 0; } } } res = dp[row - 1][column - 1]; return res; } };
//这道题就是在后一道的基础上增加了对当前路况的判断,对于边界的处理就是一旦出现障碍,边界之后的方案数变为0。因为出现障碍边界就不能达到终点。
//第二就是对于矩形中间节点的判断,中间一旦出现障碍,就是当前到达当前节点的方案数为0,因为这个点是障碍点不能达到。
相关文章推荐
- [Leetcode] Unique Paths II
- [LeetCode] Unique Paths II 不同的路径之二
- [LeetCode]Unique Paths II
- LeetCode | Unique Paths II(唯一路径II)
- LeetCode Unique Paths II
- LeetCode Unique Paths II
- [leetcode] Unique Paths II
- LeetCode 63 Unique Paths II
- LeetCode 95. Unique Binary Search Trees II
- [LeetCode] Unique Paths && Unique Paths II && Minimum Path Sum (动态规划之 Matrix DP )
- 【LeetCode】95.Unique Binary Search Trees II(Medium)解题报告
- LeetCode Unique Paths II
- LeetCode 95. Unique Binary Search Trees II
- Leetcode: 95. Unique Binary Search Trees II
- [Leetcode] #62#63 Unique Paths I & II
- [LeetCode]Unique Paths II
- leetcode 95. Unique Binary Search Trees II-分治算法|动态规划|卡特兰数
- Leetcode 95. Unique Binary Search Trees II及二叉树最大最小深度镜像树总结
- LeetCode_DP_Unique Paths II
- [LeetCode] Unique Paths II