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:

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

Example 2:

Input: m = 7, n = 3
Output: 28
想法:采用动态规划,确立状态转移表达式f(m,n)=f(m-1,n)+f(n-1,m)表示可能性。
class Solution {
public:
    int uniquePaths(int m, int n) {
        int result[m][n];
         ; i < m ; i++){
             ; j < n ; j++){
                 == i ||  == j){
                    result[i][j] = ;
                    continue;
                }
                result[i][j] = result[i-][j] + result[i][j-];
            }
        }
        ][n-];
    }
};

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. zookeeper3.4.5+Hbase1.2.6安装教程

    说明:在安装zookeeper+Hbase之前,我们应该已经将hadoop集群搭建好了(三个节点),并且验证启动成功.因为HBase是一种构建在HDFS之上的分布式.面向列的存储系*统. zookee ...

  2. CSS计数器(序列数字字符自动递增)详解———张鑫旭

    by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=4303 一.挖坟不可耻 ...

  3. 微信小程序-上传照片-多张显示

    图片就是一个简单的效果 实现 先看wxml和wxss代码 <view class='in-demand'> <view class='dema-title'> <text ...

  4. @NotNull、@NotEmpty、@NotBlank的区别

    Spring中@NotNull.@NotEmpty.@NotBlank的区别@NotNull:用于基本数据类型@NotEmpty:用于集合类@NotBlank:用于String上面

  5. 如何扩展Linux虚拟内存文件系统

    由于ArcGIS GeoAnalystics Server和Raster Analytics Server大数据分析平台都是基于Spark分析平台的,其部署服务器除了要求具有高内存特点外,也需要确保相 ...

  6. ActiveReports 报表控件V12新特性 -- 无需ETL处理,即可实现跨数据源分析数据

    ActiveReports是一款专注于 .NET 平台的报表控件,全面满足 HTML5 / WinForms / ASP.NET / ASP.NET MVC / WPF 等平台下报表设计和开发工作需求 ...

  7. terminate called after throwing an instance of 'std::bad_alloc'

    这个错误,网上搜索到的资料大多是指向内存不足或者内存碎片问题,如下链接 http://bbs.csdn.net/topics/330000462 http://stackoverflow.com/qu ...

  8. 在JavaScript文件中用jQuery方法实现日期时间选择功能

    JavaScript Document $(document).ready(function(e) { 在文本框里面显示当前日期 var date = new Date(); var nian = d ...

  9. Android--listView的divider分割线样式和边距

    1.建立一个drawable文件list_divider.xml <?xml version="1.0" encoding="utf-8"?> &l ...

  10. MySQL主从复制——主库已有数据的解决方案

    在上篇文章中我们介绍了基于Docker的Mysql主从搭建,一主多从的搭建过程就是重复了一主一从的从库配置过程,需要注意的是,要保证主从库my.cnf中server-id的唯一性.搭建完成后,可以在主 ...