题目:

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.

思路:

这道题看上去有点摸不到头脑,其实细想,到达某一点路径数就等于到达它上一点和左边点的路径数之和。这样,我们就可以建立一个二维数组,进行求解即可。

/**
* @param {number} m
* @param {number} n
* @return {number}
*/
var uniquePaths = function(m, n) {
var f=[];
for(var i=0;i<m;i++){
f[i]=[];
} for(var i=0;i<n;i++){
f[0][i]=1;
} for(var i=0;i<m;i++){
f[i][0]=1;
} for(var i=1;i<m;i++){
for(var j=1;j<n;j++){
f[i][j]=f[i-1][j]+f[i][j-1];
}
}
return f[m-1][n-1];
};

【数组】Unique Paths的更多相关文章

  1. 【数组】Unique Paths II

    题目: Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. H ...

  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. 62. Unique Paths && 63 Unique Paths II

    https://leetcode.com/problems/unique-paths/ 这道题,不利用动态规划基本上规模变大会运行超时,下面自己写得这段代码,直接暴力破解,只能应付小规模的情形,当23 ...

  5. 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 ...

  6. Java for LeetCode 062 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. 62. Unique Paths

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

  8. 【LeetCode练习题】Unique Paths

    Unique Paths A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagra ...

  9. Leetcode 动态规划 Unique Paths

    本文为senlie原创.转载请保留此地址:http://blog.csdn.net/zhengsenlie Unique Paths Total Accepted: 17915 Total Submi ...

随机推荐

  1. (博弈 sg入门)kiki's game -- hdu -- 2147

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=2147 题意: 在一个n*m的棋盘上,从  (1,m),即右上角开始向左下角走. 下棋者只能往左边(lef ...

  2. Window vista 以上制作自定义证书并为端口配置ssl

    此处的关键在于证书需要分两步,不然在配置ssl时总会有错误.也许makecert命令也会有些玄机,但是管他呢,请按以下步骤和命令配置,几分钟就可成功: 证书制作: 1,  在开始/所有程序(或其他地方 ...

  3. [SAP]编辑表

    SAP中,不能直接修改表的内容,可以用SE16N进行调试打开编辑选项,进行修改. (注:直接修改数据有风险,首先要确认修改数据的关系或做好必要的备份) 1:运行SE16N ,填好表名,参数等. 2:在 ...

  4. easyui 导出 excel

    <div style="margin-bottom:5px" id="tb"> <a href="#" class=&qu ...

  5. vscode怎样新建项目

    首先,vscode本身没有新建项目的选项,所以要先创建一个空的文件夹喔.   然后打开vscode,再在vscode里面打开文件夹,这样才可以创建项目.   选择之前创建的空文件将作为vscode的文 ...

  6. 基于ASP.NET的MVC框架下的MvcPaper分页控件的使用技术

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using Webdiyer. ...

  7. [uwp]自定义图形裁切控件

    开始之前,先上一张美图.图中的花叫什么,我已经忘了,或者说从来就不知道,总之谓之曰“野花”.只记得花很美,很香,春夏时节,漫山遍野全是她.这大概是七八年前的记忆了,不过她依旧会很准时的在山上沐浴春光, ...

  8. Android中Textview显示Html,图文混排,支持图片点击放大

    本文首发于网易云社区 对于呈现Html文本来说,Android提供的Webview控件可以得到很好的效果,但使用Webview控件的弊端是效率相对比较低,对于呈现简单的html文本的话,杀鸡不必使用牛 ...

  9. NOI2009 区间

    题目链接:戳我 60分部分分还是很好拿的,排序(按照左端点为第一关键字,右端点为第二关键字)之后一个\(O(n^2)\),暴力判交,更新最小值,就可以水过前12个测试点. #include<io ...

  10. 【ocp-12c】最新Oracle OCP-071考试题库(41题)

    41.(8-14) choose two View the Exhibit and examine the structure of the ORDERS table. The columns ORD ...