题目

https://oj.leetcode.com/problems/unique-paths/
 
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?
 

思路

每个到达终点的方案需要向右m-1步,向下n-1步,一共m+n-2步;
从组合角度,可以理解为从m+n-2中选择m-1步向右走,剩下n-1步向下走。
 

代码

 1 class Solution:
 2     # @return an integer
 3     def uniquePaths(self, m, n):
 4         return int(self.combination(m+n-2, n-1))
 5     
 6     def combination(self, n, k):
 7         res = 1.0
 8         for i in range(1, k+1):
 9             res = res * (n - k + i) / i
         return res
 
参考地址
1. https://oj.leetcode.com/discuss/9110/my-ac-solution-using-formula

【leetcode】62. Uniqe Paths的更多相关文章

  1. 【LeetCode】62. Unique Paths 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/unique-pa ...

  2. 【LeetCode】62. Unique Paths

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

  3. 【leetcode】62.63 Unique Paths

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

  4. 【LeetCode】63. Unique Paths II 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/unique-pa ...

  5. 【一天一道LeetCode】#62. Unique Paths

    一天一道LeetCode系列 (一)题目 A robot is located at the top-left corner of a m x n grid (marked 'Start' in th ...

  6. 【LeetCode】980. Unique Paths III解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 回溯法 日期 题目地址:https://leetco ...

  7. 【LeetCode】797. All Paths From Source to Target 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 回溯法 日期 题目地址:https://leetco ...

  8. 【LeetCode】63. Unique Paths II

    Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are added to ...

  9. 【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). ...

随机推荐

  1. Shader Forge 刀光溶解

    实际特效时,时间可以控制vertex color.a,shader forge 还只是玩具,试验用具,离商业产品质量还有差距. 其实,有技术美术的画,很多问题,美术能自己解决,都是一些欠缺通道的问题, ...

  2. 2012蓝桥杯本科组C/C++预赛题

    微生物增殖 假设有两种微生物 X 和 Y X出生后每隔3分钟分裂一次(数目加倍),Y出生后每隔2分钟分裂一次(数目加倍). 一个新出生的X,半分钟之后吃掉1个Y,并且,从此开始,每隔1分钟吃1个Y. ...

  3. Cleaning Shifts(区间覆盖)

    /* http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?pid=1019&ojid=1&cid=10 题目: 给定一个时 ...

  4. poj2926 曼哈顿最远距离

    题目链接:http://poj.org/problem?id=2926 #include<cstdio> #include<cstring> #include<cmath ...

  5. [转]机器学习&数据挖掘笔记_16(常见面试之机器学习算法思想简单梳理)

    机器学习&数据挖掘笔记_16(常见面试之机器学习算法思想简单梳理) 转自http://www.cnblogs.com/tornadomeet/p/3395593.html 前言: 找工作时(I ...

  6. paip.输入法编程----删除双字词简拼

    paip.输入法编程----删除双字词简拼 作者Attilax ,  EMAIL:1466519819@qq.com  来源:attilax的专栏 地址:http://blog.csdn.net/at ...

  7. jni那点事

    今天说一下在jni开发中常另新手迷惑的JNIEnv这个东西 比如一个c语言的函数 JNIEXPORT jstring JNICALL Java_com_mmmmar_nativethread_Main ...

  8. 《Android开发艺术探索》读书笔记 (6) 第6章 Android的Drawable

    本节和<Android群英传>中的第六章Android绘图机制与处理技巧有关系,建议先阅读该章的总结 第6章 Android的Drawable 6.1 Drawable简介 (1)Andr ...

  9. 在Linux上怎么安装和配置Apache Samza

    samza是一个分布式的流式数据处理框架(streaming processing),它是基于Kafka消息队列来实现类实时的流式数据处理的.(准确的说,samza是通过模块化的形式来使用kafka的 ...

  10. 【开源java游戏框架libgdx专题】-07-文件处理

    介绍:文件处理在不同平台的文件管理是略有差异的 Desktop(Windows,Linux,Mac OS X等等):在桌面系统中,文件系统是一个大块的内存.文件可以通过当前的工作目录或者绝对路径被引用 ...