LeetCode-Unique Paths
来源:互联网 发布:php curl模拟post 编辑:程序博客网 时间:2024/06/05 16:13
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).
The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).
How many possible unique paths are there?
Above is a 3 x 7 grid. How many possible unique paths are there?
解题报告:动态规划的基础题,用一个数组存储到各个点的有多少条路。
如果数组没被存入数字,那就存储,这条路前一点的数字。如果已被存入数字,那就加入这条路前一点的数字。
class Solution {public: int uniquePaths(int m, int n) { int temp[m][n]; for (size_t i = 0; i != m; i++) for(size_t j = 0; j != n; j++) temp[i][j] = -1; temp[0][0] = 1; for (size_t i = 0; i != m; i++) { for(size_t j = 0; j != n; j++) { if(j != n-1) { if(temp[i][j+1] != -1) temp[i][j+1] += temp[i][j]; else temp[i][j+1] = temp[i][j]; } if(i != m-1) { if(temp[i+1][j] != -1) temp[i+1][j] += temp[i][j]; else temp[i+1][j] = temp[i][j] ; } } } return temp[m-1][n-1]; }};
Note: m and n will be at most 100.
0 0
- leetcode Unique Paths && Unique Paths
- Leetcode-Unique Paths&Unique PathsII
- [LeetCode] Unique Paths and Unique Paths II
- leetcode--Unique Paths && Unique Paths ii
- leetcode--Unique Paths && Unique Paths ii
- 【Leetcode】【python】Unique Paths/Unique Paths II
- LeetCode: Unique Paths
- LeetCode: Unique Paths II
- [Leetcode] Unique Paths
- [Leetcode] Unique Paths II
- LeetCode : Unique Paths
- LeetCode : Unique Paths II
- leetcode 9: Unique Paths
- [LeetCode] Unique Paths
- [LeetCode] Unique Paths II
- [LeetCode]Unique Paths
- [LeetCode]Unique Paths II
- [LeetCode] Unique Paths
- ListView回收机制相关分析
- Linux chmod命令
- C++ 编程思想(第一卷)阅读总结
- 编译器学习--文法的类型
- [Solr实践]Solr Cache使用介绍及分析
- LeetCode-Unique Paths
- UVN相机模型
- ural 2018. The Debut Album 滚动数组dp
- zookeeper 安装
- 我到底要选择一种什么样的生活方式,度过这一辈子呢:人生自由与职业发展方向(上)
- html 元素隐藏设置时 display和visibility的区别
- 黑马程序员Android第55期——html
- JQuery中的id选择器含有特殊字符时,不能选中dom元素的解决方法
- lea和offset、addr