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. iOS开发之 -- CocoPods的安装和使用

    以前项目中使用过Pods 1.0,最近项目中也有用到,因为很长时间没用了,所以配置了下,谁知道,中间出现了不少坑,特记录在此博客,其实pods的使用也就是几个终端命令而已,可能随着系统的升级,以前的终 ...

  2. 二、Android Studio使用——导入jar包,运行、debug都不是问题

    [新建AndroidStudio工程,lib导入jar包]   我们的项目代码都在app里面,可以看作是一个Model.   src 下面除了我们的代码之外,还有单元测试. 把JAR复制到libs文件 ...

  3. 【黑金原创教程】【TimeQuest】【第一章】TimeQuest 静态时序分析模型的概念

      声明:本文为黑金动力社区(http://www.heijin.org)原创教程,如需转载请注明出处,谢谢! 黑金动力社区2013年原创教程连载计划: http://www.cnblogs.com/ ...

  4. MongoDB插入多条数据

    刚开始学mongodb,只知道几个命令,insert插入也只能一条一条插入,而在实际情况下数据一般都非常多,刚开始想直接上传json文件,网上搜了n多方法发现这种方法不好弄,然后就想着要么一下子把多条 ...

  5. cocos2dx-draw绘制

    [一]:函数   //1.设置绘制颜色 1.ccDrawColor4B("红","绿","蓝","透明"); //2.设 ...

  6. lofter个人网站文艺愤青下载

    lofter地址→点击访问 你妹扫我        生成地址

  7. 160229-02、Sublime Text 3 快捷键总结

    选择类 Ctrl+D 选中光标所占的文本,继续操作则会选中下一个相同的文本. Alt+F3 选中文本按下快捷键,即可一次性选择全部的相同文本进行同时编辑.举个栗子:快速选中并更改所有相同的变量名.函数 ...

  8. CH5202 自然数拆分Lunatic版【完全背包】

    5202 自然数拆分Lunatic版 0x50「动态规划」例题 描述 给定一个自然数N,要求把N拆分成若干个正整数相加的形式,参与加法运算的数可以重复.求拆分的方案数 mod 2147483648的结 ...

  9. Servlet------>jsp自定义标签4(重复标签体)

    4.控制标签体内容执行五次(tld中的配置,和jsp我就省略了,详细请看jsp自定义标签1)这里这个方法是继承了tag接口的实现类,这个实现类里不只实现了tag接口,还有tag接口的子接口,也就是It ...

  10. Netty 粘包/半包原理与拆包实战

    Java NIO 粘包 拆包 (实战) - 史上最全解读 - 疯狂创客圈 - 博客园 https://www.cnblogs.com/crazymakercircle/p/9941658.html 本 ...