【题目】

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. ubuntu 14.04 postgresql 的总结

    1)为了允许远程连接: a) http://askubuntu.com/questions/423165/remotely-access-postgresql-database To open the ...

  2. python cook 整理

    1.字符串分割 单个分隔符    'abc'.split('b')  >> ['a','c'] 多个分隔符    re.split(r'[b,d]','abcde') >>&g ...

  3. LeetCode--232--用栈实现队列

    问题描述: 使用栈实现队列的下列操作: push(x) -- 将一个元素放入队列的尾部. pop() -- 从队列首部移除元素. peek() -- 返回队列首部的元素. empty() -- 返回队 ...

  4. spark app

    使用Spark和Scala分析Apache访问日志 http://www.jdon.com/bigdata/analyzing-apache-access-logs-files-spark-scala ...

  5. Build Castles(构建城堡)

    Charlemagne, the King of Frankie, 英文描述 请参考图片中的说明. 中文描述 根据给出的数组确定能够盖多少城堡. 思路和点评 我不能确定我的思路是正确的,也欢迎大家参与 ...

  6. ansible管理windows (发送文件)

    https://github.com/ansible/ansible/raw/devel/examples/scripts/ConfigureRemotingForAnsible.ps1 环境: 服务 ...

  7. python-day81--Ajax

    一.准备知识:json 1.什么是json? JSON(JavaScript Object Notation, JS 对象标记) 是一种轻量级的数据交换格式.任何的语言之间都可以用json进行数据的交 ...

  8. HDU-6386-最短路

    Age of Moyu Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Tot ...

  9. HTML 5 <span> 标签

    标签定义及使用说明 <span> 用于对文档中的行内元素进行组合. <span> 标签没有固定的格式表现.当对它应用样式时,它才会产生视觉上的变化.如果不对 <span& ...

  10. 17. Letter Combinations of a Phone Number C++回溯法

    简单的回溯法! class Solution { public: void backTrack(string digits, vector<string> words, string an ...