[LeetCode]62. Unique Paths
来源:互联网 发布:服装设计软件cad 编辑:程序博客网 时间:2024/06/05 11:26
Unique Paths
- 问题描述
- 代码
- 代码分析
问题描述
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?
代码
class Solution {public: int a[101][101] = {0}; int uniquePaths(int m, int n) { a[1][1] =1; for(int i = 1; i<=m;++i) for(int j = 1; j<=n;++j) if(!(i == 1 && j == 1)) a[i][j] = a[i-1][j]+a[i][j-1]; return a[m][n]; }};
代码分析
以3*3的矩阵为例
图中为到各个位置有多少种方法。
可以分析+观察可以得出
到(i,j)的方法个数为所有前一步所走的方法之和
例如f(3,2) = f(3,1)+f(2,2) = 1+2=3
则得到递推公式 f(i,j) = f(i-1,j)+f(i,j-1)
阅读全文
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
- 云片短信平台ASP版程序网站使用方法
- html中怎么定义搜索框?html中search类型?
- leetCode:Non-overlapping Intervals
- 连续第十一天总结
- Springboot项目使用Nginx 并配置 HTTPS
- [LeetCode]62. Unique Paths
- Bootstrap学习笔记-css组件Hello_yihao的博客
- 线程之suspend和resume方法
- Visual Studio Ultimate 2013 Update5 中文版/英文版 下载 CD-KEY
- Dlib库landmark算法解析(ERT 集成回归树)
- redis学习系列(八)--redis-RDB基础
- Spring项目处理异常
- Windows编程基础--第7节 来吧,VS 2010
- 连续第十二总结