【题目】

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?

【思路】

机器人每次向左或者向下走一步,在规则的长方形里有多少种方法到达终点。

动态规划,tmp[i][j]=tmp[i-1][j]+tmp[i][j-1],初始化状态只有一条路时只有以一种方法。

【代码】

class Solution {
  public int uniquePaths(int m, int n) {
    int [][]dp=new int[m+1][n+1];
    dp[0][0]=0;
    for(int i=0;i<m;i++){
      dp[i][0]=1;
    }
    for(int j=0;j<n;j++){
      dp[0][j]=1;
    }
    for(int i=1;i<m;i++){
      for(int j=1;j<n;j++){
        dp[i][j]=dp[i-1][j]+dp[i][j-1];
      }
    }
    return dp[m-1][n-1];
  }
}

[Leetcode 62]机器人走路Unique Path 动态规划的更多相关文章

  1. LeetCode 62,从动态规划想到更好的解法

    本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是LeetCode专题第36篇文章,我们一起来看下LeetCode的62题,Unique Paths. 题意 其实这是一道老掉牙的题目了 ...

  2. [LeetCode]题解(python):062 Unique path

    题目来源 https://leetcode.com/problems/unique-paths/ A robot is located at the top-left corner of a m x  ...

  3. LeetCode 63. Unique Path II(所有不同路径之二)

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

  4. [leetcode]62. 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. 一款html5和css3实现的小机器人走路动画

    之前介绍了好多款html5和css3实现的动画,今天要给大家带来一款html5和css3实现的小机器人走路动画.该实例的人物用html5绘画的,动画效果是html5和css3实现的.一起看下效果图. ...

  6. LeetCode(64) Minimum Path Sum

    题目 Total Accepted: 47928 Total Submissions: 148011 Difficulty: Medium Given a m x n grid filled with ...

  7. leetcode63—Unique Path II

    A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...

  8. Leetcode 91. Decode Ways 解码方法(动态规划,字符串处理)

    Leetcode 91. Decode Ways 解码方法(动态规划,字符串处理) 题目描述 一条报文包含字母A-Z,使用下面的字母-数字映射进行解码 'A' -> 1 'B' -> 2 ...

  9. Unique Path AGC 038 D

    Unique Path AGC 038 D 考虑如果两个点之间只能有一个边它们就把它们缩起来,那么最后缩起来的每一块都只能是一棵树. 如果两个点之间必须不止一个边,并且在一个连通块,显然无解. 首先把 ...

随机推荐

  1. 批标准化 Batch Normalization

    2018-12-05 20:28:15 在机器学习领域有一个很重要的假设,即独立同分布假设,也就是说训练集和测试集是满足相同分布的,这是通过训练数据获得的模型能够在测试集获得好的效果的一个基本保障.而 ...

  2. C# 递归缩小图片

    需求:图片太大,上传到服务器会非常占用服务器空间,而系统又不要求高清图片,于是就通过递归的方式让图片每次减少10%的大小,当图片大小小于100k的时候就保存在本地,核心代码如下: class Prog ...

  3. ffmpeg 加 logo

    How to add a watermark or logo to any corner or the center of a video with FFMPEG. ffmpeg –i video.m ...

  4. jdk8新特性:在用Repository实体查询是总是提示要java.util.Optional, 原 Inferred type 'S' for type parameter 'S' is not within its bound;

    jdk8新特性:在用Repository实体查询是总是提示要java.util.Optional 在使用springboot 方法报错: Inferred type 'S' for type para ...

  5. tchart2

  6. find_first_zero_bit在使用gcc 4.2.4 编译时,需要保护%eax

    1.3.100 find_first_zero_bit在使用gcc 4.2.4 编译时,需要保护%eax find_first_zero_bit 修订后: /* * Find-bit routines ...

  7. 架构探险笔记11-与Servlet API解耦

    Servlet API解耦 为什么需要与Servlet API解耦 目前在Controller中是无法调用Servlet API的,因为无法获取Request与Response这类对象,我们必须在Di ...

  8. SWUST OJ(955)

    单链表上查找算法的实现 #include <stdio.h> #include <stdlib.h> typedef struct LinkNode //单链表节点结构的定义 ...

  9. rsync未授权访问漏洞利用

    漏洞描述:rsync是Linux系统下的数据镜像备份工具,使用快速增量备份工具Remote Sync可以远程同步,支持本地复制,或者与其他ssh,rsync主机同步.也就是说如果你可以连接目标IP的r ...

  10. 第一阶段——站立会议总结DAY10

    1.昨天做了什么:找到了一些模板,把自己的修改了修改,排版了一下. 2.今天准备做什么:做最后的整理,添加一些小图标一些的.还要把按钮的字体换成红色. 3.遇到的困难:一般定义的文字和下拉菜单的文字的 ...