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 7 x 3 grid. How many possible unique paths are there?

Note: m and n will be at most 100.

Example 1:

  1. Input: m = 3, n = 2
  2. Output: 3
  3. Explanation:
  4. From the top-left corner, there are a total of 3 ways to reach the bottom-right corner:
  5. 1. Right -> Right -> Down
  6. 2. Right -> Down -> Right
  7. 3. Down -> Right -> Right

Example 2:

  1. Input: m = 7, n = 3
  2. Output: 28
  1. 想法:采用动态规划,确立状态转移表达式f(m,n)=f(m-1,n)+f(n-1,m)表示可能性。
  1. class Solution {
  2. public:
  3. int uniquePaths(int m, int n) {
  4. int result[m][n];
  5. ; i < m ; i++){
  6. ; j < n ; j++){
  7. == i || == j){
  8. result[i][j] = ;
  9. continue;
  10. }
  11. result[i][j] = result[i-][j] + result[i][j-];
  12. }
  13. }
  14. ][n-];
  15. }
  16. };

leetcode62—Unique Paths的更多相关文章

  1. [LeetCode62]Unique Paths

    题目: A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). ...

  2. leetcode-62. Unique Paths · DP + vector

    题面 A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). ...

  3. Leetcode62.Unique Paths不同路径

    一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为"Start" ). 机器人每次只能向下或者向右移动一步.机器人试图达到网格的右下角(在下图中标记为" ...

  4. [Swift]LeetCode62. 不同路径 | Unique Paths

    A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...

  5. [LeetCode] Unique Paths II 不同的路径之二

    Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...

  6. [LeetCode] Unique Paths 不同的路径

    A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...

  7. Leetcode Unique Paths II

    Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...

  8. Unique Paths II

    这题在Unique Paths的基础上增加了一些obstacle的位置,应该说增加的难度不大,但是写的时候对细节的要求多了很多,比如,第一列的初始化会受到之前行的第一列的结果的制约.另外对第一行的初始 ...

  9. LEETCODE —— Unique Paths II [动态规划 Dynamic Programming]

    唯一路径问题II Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are ...

随机推荐

  1. 清空mysql数据表中的所有数据

    - 清空全部数据,不写日志,不可恢复,速度极快 truncate table_name;   -- 清空全部数据,写日志,数据可恢复,速度慢 delete from 表名     详情请查看区别

  2. hightcharts 如何修改legend图例的样式

    正常情况下hightcharts 的legend图形是根据他本身默认的样式来显示,如下图 这几个图形的形状一般也是改不了的,只能根据图表的类型显示默认的.但是我们可以通过修改默认的样式来展示一些可以实 ...

  3. js-函数柯里化

    内容来自曾探,<JavaScript设计模式与开发实践>,P49 函数柯里化(function currying)又称部分求值.一个currying的函数首先会接受一些参数,接受了这些参数 ...

  4. 【代码笔记】iOS-JSONKit的使用

    一,工程图. 二,代码. #import "RootViewController.h" //为JSONKit添加头文件 #import "JSONKit.h" ...

  5. Jquery UI Custom的兼容问题

    在测试过程中遇到Jquery UI Dialog异常的情况,表现为在拖拽Dialog标头时出现Dialog跳跃的问题,对比jquery ui与jquery在协调工作情况下的运行情况. 1.环境: Wi ...

  6. 一文读懂商业智能(BI):企业数据分析的中枢

    商业智能(BI)大家可能早已耳熟能详.从早期的报表自动化,到现在的复杂灵活分析,多平台支持,优秀的人机互动,多数据抽取,大数据整合,甚至和当下最火的人工智能都有结合点.可能一提到BI,大家都会自然而然 ...

  7. SQLServer 2008(R2)如何开启数据库的远程连接

    SQL Server 2008 R2如何开启数据库的远程连接 by:授客 QQ:1033553122 SQL Server 2008默认是不允许远程连接的,如果想要在本地用SSMS连接远程服务器上的S ...

  8. Git执行过程中出现问题及解决方法

    not-fast-forward https://help.github.com/articles/dealing-with-non-fast-forward-errors/

  9. 【转】qt-vs-addin:Qt4和Qt5之VS插件如何共存与使用

    原则上,两者是不可以同时存在的,但是如果都安装了,该如何分别使用他们呢? Qt4 Visual Studio Add-in:官网可以下载安装程序,qt-vs-addin-1.1.11-opensour ...

  10. LeetCode题解之Merge k Sorted Lists 解法二

    1.题目描述 2.分析 利用 vector 存储指针,同时合并k个链表. 3.代码 ListNode* mergeKLists(vector<ListNode*>& lists) ...