一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为“Start” )。

机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角(在下图中标记为“Finish”)。

问总共有多少条不同的路径?

例如,上图是一个7 x 3 的网格。有多少可能的路径?

说明:m 和 n 的值均不超过 100。

示例 1:

输入: m = 3, n = 2 输出: 3 解释: 从左上角开始,总共有 3 条路径可以到达右下角。 1. 向右 -> 向右 -> 向下 2. 向右 -> 向下 -> 向右 3. 向下 -> 向右 -> 向右

示例 2:

输入: m = 7, n = 3 输出: 28

当i == 0或者 j == 0的时候,机器人只有一种走法。

其他时候,机器人可以从[i][j - 1]或者[i - 1][j]的地方走来

class Solution {
public:
int uniquePaths(int m, int n)
{
vector<vector<int> > dp(m, vector<int>(n, 0));
for(int i = 0; i < m; i++)
{
for(int j = 0; j < n; j++)
{
if(i == 0)
dp[i][j] = 1;
else if(j == 0)
dp[i][j] = 1;
else
dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
}
}
return dp[m - 1][n - 1];
}
};

Leetcode62.Unique Paths不同路径的更多相关文章

  1. [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 ...

  2. LeetCode 62. Unique Paths不同路径 (C++/Java)

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

  3. [LeetCode] 62. Unique Paths 唯一路径

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

  4. 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). ...

  5. [LeetCode62]Unique Paths

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

  6. [leetcode]62. 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. 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 ...

  8. 062 Unique Paths 不同路径

    机器人位于一个 m x n 网格的左上角, 在下图中标记为“Start” (开始).机器人每次只能向下或者向右移动一步.机器人试图达到网格的右下角,在下图中标记为“Finish”(结束).问有多少条不 ...

  9. 62. Unique Paths不同路径

    网址:https://leetcode.com/problems/unique-paths/ 第一思路是动态规划 通过观察,每一个格子的路线数等于相邻的左方格子的路线数加上上方格子的路线数 于是我们就 ...

随机推荐

  1. Store工作原理

  2. 搭建一个Semantic-ui项目

    一.进入到项目目录 npm init 二.安装semantic-ui npm install semantic-ui --save 三.编译输出semantic-ui cd  ./semantic g ...

  3. Touching segments(数据结构)

    题目链接 Problem Statement Your Maths professor is a very nice guy, but he sometimes comes up with not s ...

  4. 深入学习:Windows下Git新手教程(下)

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/huangyabin001/article/details/35840591 声明:因为本人对于Git ...

  5. C# 全局Hook在xp上不回调

    最近做了个捕捉全局鼠标,获取目标窗体内的控件文本信息,点击的按钮信息.用的全局钩子.在win10上运行正常,部署到xp系统上就没有反应.查了些资料,解决了此问题. 原本安装钩子的写法如下: Nativ ...

  6. retrying模块的使用

    安装模块:pip3 install retrying 使用方式: 使用retrying模块提供的retry模块 通过装饰器的方式使用,让装饰器的函数反复的执行 retry可以传入参数stop_max_ ...

  7. 使用Maven编译运行Storm入门代码(Storm starter)(转)

    Storm 官方提供了入门代码(Storm starter),即 Storm安装教程 中所运行的实例(storm-starter-topologies-0.9.6.jar),该入门代码位于 /usr/ ...

  8. UVA11107 Life Forms SA模板

    Life Forms Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 16827   Accepted: 4943 Descr ...

  9. js 高亮显示关键字

    示例: var defaultEmphasisHandler = function(keyword, data){ var regex = RegExp("("+keyword.r ...

  10. SSM11-Redis---jedis的使用方法以及缓存同步

    1. Jedis 需要把jedis依赖的jar包添加到工程中.Maven工程中需要把jedis的坐标添加到依赖. 推荐添加到服务层.E3-content-Service工程中. 1.1. 连接单机版 ...