博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
62. Unique Paths
阅读量:4328 次
发布时间:2019-06-06

本文共 1321 字,大约阅读时间需要 4 分钟。

m*n的格子里面,机器人在左上角,每次行动向下或者想右一格,请问可能的方案

"""62. Unique PathsMedium113781FavoriteShareA 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?https://assets.leetcode.com/uploads/2018/10/22/robot_maze.pngAbove 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 = 2Output: 3Explanation:From the top-left corner, there are a total of 3 ways to reach the bottom-right corner:1. Right -> Right -> Down2. Right -> Down -> Right3. Down -> Right -> RightExample 2:Input: m = 7, n = 3Output: 28"""

动规即可

class Solution:    def uniquePaths(self, m, n):        """        :type m: int        :type n: int        :rtype: int        """        mat = [[0 for i in range(n)]for j in range(m)]        mat[0][0] = 1        for j in range(1, n):            mat[0][j] = 1        for i in range(1, m):            mat[i][0] = 1        for i in range(1, m):            for j in range(1, n):                mat[i][j] = mat[i-1][j] + mat[i][j-1]        return mat[m-1][n-1]

 

转载于:https://www.cnblogs.com/mangmangbiluo/p/10181063.html

你可能感兴趣的文章
POJ 1141 Brackets Sequence
查看>>
Ubuntu 18.04 root 使用ssh密钥远程登陆
查看>>
Servlet和JSP的异同。
查看>>
虚拟机centOs Linux与Windows之间的文件传输
查看>>
ethereum(以太坊)(二)--合约中属性和行为的访问权限
查看>>
IOS内存管理
查看>>
middle
查看>>
[Bzoj1009][HNOI2008]GT考试(动态规划)
查看>>
Blob(二进制)、byte[]、long、date之间的类型转换
查看>>
OO第一次总结博客
查看>>
day7
查看>>
iphone移动端踩坑
查看>>
vs无法加载项目
查看>>
Beanutils基本用法
查看>>
玉伯的一道课后题题解(关于 IEEE 754 双精度浮点型精度损失)
查看>>
《BI那点儿事》数据流转换——百分比抽样、行抽样
查看>>
哈希(1) hash的基本知识回顾
查看>>
Leetcode 6——ZigZag Conversion
查看>>
dockerfile_nginx+PHP+mongo数据库_完美搭建
查看>>
Http协议的学习
查看>>