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

Note: m and n will be at most 100.

设mxn的表格,前面增加一列为mX(n+1), 注意对于

第i行第j列的元素path[i][j],其路径前一个点只有path[i-1][j]和path[i][j-1]两种可能

即path[i][j] =path[i-1][j] + path[i][j-1],而path[i-1][j]为上面一行的元素,而path[i][j-1]为其左边的元素

当更新path[i][j]时,此时左边元素已经更新,只需要用滚动数组实现即可

path[0] path[1] path[2] path[3] path[4] path[5] path[6] path[7]
path[0] path[1]  path[2]=path[1]+path[2]          
path[0]              
int unique(int m, int n){
vector<int> path(n+,);
path[] = ;
for(int i = ; i < m; ++ i){
for(int j = ; j<= n ; ++ j){
path[j]+=path[j-];
}
}
return path[n];
}

Leetcode Unique Paths的更多相关文章

  1. LeetCode: Unique Paths II 解题报告

    Unique Paths II Total Accepted: 31019 Total Submissions: 110866My Submissions Question Solution  Fol ...

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

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

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

  4. LeetCode: Unique Paths I & II & Minimum Path Sum

    Title: https://leetcode.com/problems/unique-paths/ A robot is located at the top-left corner of a m  ...

  5. [leetcode]Unique Paths II @ Python

    原题地址:https://oj.leetcode.com/problems/unique-paths-ii/ 题意: Follow up for "Unique Paths": N ...

  6. [leetcode]Unique Paths @ Python

    原题地址:https://oj.leetcode.com/problems/unique-paths/ 题意: A robot is located at the top-left corner of ...

  7. [LeetCode] Unique Paths && Unique Paths II && Minimum Path Sum (动态规划之 Matrix DP )

    Unique Paths https://oj.leetcode.com/problems/unique-paths/ A robot is located at the top-left corne ...

  8. Leetcode Unique Paths II

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

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

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

随机推荐

  1. Weblogic监控指标

    http://blog.csdn.net/a_dreaming_fish/article/details/50592042

  2. SQL中的JOIN类型解释(CROSS, INNER,OUTER),关键字ON,USING

    书上讲得明白,解了不少迷惑. SELECT e.fname, e.lname, d.name FROM employee AS e INNER JOIN department AS d ON e.de ...

  3. 同一服务器配置DataGuard

    实验环境:1.虚拟机VMware Server 1.0.62.操作系统:ora10g@linux5 /home/oracle$ cat /etc/redhat-releaseRed Hat Enter ...

  4. POJ3321 Apple Tree(树状数组)

    先做一次dfs求得每个节点为根的子树在树状数组中编号的起始值和结束值,再树状数组做区间查询 与单点更新. #include<cstdio> #include<iostream> ...

  5. postgresql设置默认的search_path

    -- Use this to show the current search_path -- Should return: "$user",public SHOW search_p ...

  6. VS2010和matlab2010混合编程中char16_t重定义的问题

    原因是VS2010中的yvals.h添加了char16_t的定义,而Matlab的matrix.h也包含对char16_t的定义,所以同时包含这两个头文件的话,会导致重复定义char16_t的错误.只 ...

  7. GitHub 使用教程图文详解(转)

    大纲: 一.前言 二.GitHub简介 三.注册GitHub账号 四.配置GitHub 五.使用GitHub 六.参与GitHub中其它开源项目 七.总结 注,GitHub官网:https://git ...

  8. Android入门开发之SD卡读写操作(转)

    SD卡的读写是我们在开发android 应用程序过程中最常见的操作.下面介绍SD卡的读写操作方式: 1. 获取SD卡的根目录 String  sdCardRoot = Environment.getE ...

  9. ubuntu12.04 安装eclipse

    1:去官网下载最新版的eclipse for linux; 2:cd  /usr/local 用命令 sudo mkdir eclipse 建立一个Eclipse的目录 3:将下载的文件copy到ec ...

  10. Arduino101学习笔记(七)—— 时间API

    1.毫秒时间 获取机器运行的时间长度, 单位毫秒. 系统最长的记录时间为9小时22分, 如果超出时间将从0开始. 警告: 时间为 unsigned long类型, 如果用 int 保存时间将得到错误结 ...