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.

r如果用公式的话 就是 C(X+Y 选X)

 class Solution {
public int uniquePaths(int m, int n) {
int[][] dp = new int[m][n]; for(int i =0;i<m;i++){
for (int j = 0;j < n;j++){
if(i==0&&j==0)
dp[i][j]=1;
else if(i==0)
dp[i][j] = dp[i][j-1];
else if(j==0)
dp[i][j] = dp[i-1][j];
else
dp[i][j] = dp[i-1][j] + dp[i][j-1];
}
}
return dp[m-1][n-1];
}
}
 class Solution {
public int uniquePaths(int m, int n) {
int[][] dp = new int[m][n];
for(int i = 0;i<m;i++)
dp[i][0] = 1;
for(int i = 0;i<n;i++)
dp[0][i] = 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];
}
}

62. Unique Paths (走棋盘多少种不同的走法 动态规划)的更多相关文章

  1. leetcode 62. Unique Paths 、63. Unique Paths II

    62. Unique Paths class Solution { public: int uniquePaths(int m, int n) { || n <= ) ; vector<v ...

  2. 刷题62. Unique Paths

    一.题目说明 题目62. Unique Paths,在一个m*n矩阵中,求从左上角Start到右下角Finish所有路径.其中每次只能向下.向右移动.难度是Medium! 二.我的解答 这个题目读读题 ...

  3. [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 ...

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

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

  6. [leetcode] 62 Unique Paths (Medium)

    原题链接 字母题 : unique paths Ⅱ 思路: dp[i][j]保存走到第i,j格共有几种走法. 因为只能走→或者↓,所以边界条件dp[0][j]+=dp[0][j-1] 同时容易得出递推 ...

  7. LeetCode 62. Unique Paths不同路径 (C++/Java)

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

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

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

  9. LeetCode OJ 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 ...

随机推荐

  1. RESTful作用与特性

    最近在项目中要使用rest风格的设计,学习了一下. 知乎网友说的一句话精确的解释了REST: URL定位资源,用HTTP动词(GET,POST,DELETE,DETC)描述操作-(https://ww ...

  2. iOS 7 新特性:视图控制器切换API

    本文转载至 http://blog.jobbole.com/51588/ 本文由 伯乐在线 - studentdeng 翻译自 Chris Eidhof.欢迎加入技术翻译小组.转载请参见文章末尾处的要 ...

  3. JSON和对象之前的相互转换

    package com.jxjson.com; import android.util.Log; import org.json.JSONArray; import org.json.JSONExce ...

  4. Fiddler实现手机抓包——小白入门 - 做一个不动声色的大人

    手机用fiddler抓包 电脑最好是笔记本,这样能和手机保持统一局域网内:其他不多说,直接说步骤了. 一.对PC(笔记本)参数进行配置    1. 配置fiddler允许监听到https(fiddle ...

  5. spring容器加载完毕做一件事情(利用ContextRefreshedEvent事件)

    关键字:spring容器加载完毕做一件事情(利用ContextRefreshedEvent事件) 应用场景:很多时候我们想要在某个类加载完毕时干某件事情,但是使用了spring管理对象,我们这个类引用 ...

  6. log4j日志服务器配置

    可参考的文章: http://www.jb51.net/article/89597.htm http://www.jb51.net/article/41001.htm http://liuzhijun ...

  7. -bash: xxx: /bin/sh^M: bad interpreter: No such file or directory

    原因是shell脚本文件的文件格式错误 通过vi编辑器来查看文件的format格式.步骤如下: 1.首先用vi命令打开文件 vi stop.sh 2.在vi命令模式中使用 :set ff 命令 可以看 ...

  8. HDU_5534_Partial Tree

    Partial Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)To ...

  9. new Option() 创建一个option标签

    //add() 方法用于向 <select> 添加一个 <option> 元素. //new Option() 创建一个option标签 school.add(new Opti ...

  10. 新手怎么读懂一个中型的Django项目

    [前言]中型的项目是比较多的APP,肯会涉及多数据表的操作.如果有人带那就最好了,自己要先了解基本的django框架(MTV ,ORM等)师傅可以给讲解一下框架怎么组织url.py,model.py, ...