[LeetCode]62. Unique Paths
来源:互联网 发布:ceo cfo cmo 知乎 编辑:程序博客网 时间:2024/06/03 21:33
[LeetCode]62. Unique Paths
题目描述
思路
动态规划
考虑状态,当起始点与终点在同一点或同一条直线时,路径只有一条
那么当不在直线时考虑他到达相同直线的路径条数,即 dp[i][j] = dp[i][j + 1] + dp[i + 1][j]
假设对一个 2 x 3 的表格
我们可以按照上述表达计算每个格子到达终点的路径数
代码
#include <iostream>#include <vector>using namespace std;class Solution {public: int uniquePath(int m, int n) { if (m == 0 || n == 0) return 0; vector<vector<int>> dp(m, vector<int>(n)); for(int i = m - 1; i >= 0; --i) for (int j = n - 1; j >= 0; --j) { if (i == m - 1 || j == n - 1) dp[i][j] = 1; else dp[i][j] = dp[i][j + 1] + dp[i + 1][j]; } return dp[0][0]; }};int main() { Solution s; cout << s.uniquePath(1, 1) << endl; system("pause"); return 0;}
0 0
- [LeetCode]62.Unique Paths
- LeetCode --- 62. Unique Paths
- LeetCode 62.Unique Paths
- [Leetcode] 62. Unique Paths
- [leetcode] 62.Unique Paths
- [leetcode] 62.Unique Paths
- leetcode 62. Unique Paths
- Leetcode 62. Unique Paths
- [leetcode] 62. Unique Paths
- 62. Unique Paths LeetCode
- [LeetCode]62. Unique Paths
- 【LeetCOde】62. Unique Paths
- [LeetCode]62. Unique Paths
- leetcode 62. Unique Paths
- LeetCode 62. Unique Paths
- LeetCode *** 62. Unique Paths
- leetcode 62. Unique Paths
- Leetcode:62. Unique Paths
- 实验二:Newton牛顿插值法之C语言代码
- JESD79-4 第4章 SDRAM命令描述与操作(4.30-4.31)
- UITableView reloadData的本质使用
- CodeIgniter在nginx下404 not found
- Android系统上实现类似按键精灵的效果(模拟触屏点击事件)
- [LeetCode]62. Unique Paths
- java转换json
- 加载框效果
- hdu 2602 01背包
- java,抽象类与接口的区别
- 巧用Delphi制作溅射屏幕
- Java中long数据类型转化为float疑问解答
- linux 重启执行程序
- 进程与线程线程