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. SpringCloud服务发现(Eureka)简介

    Eureka是Netflix开发的服务发现框架,SpringCloud将它集成在自己的子项目spring-cloud-netflix中,实现SpringCloud的服务发现功能. 为什么要使用Eure ...

  2. [NOIP 2014复习]第二章:搜索

    一.深度优先搜索(DFS) 1.Wikioi 1066引水入城 题目描写叙述 Description 在一个遥远的国度,一側是风景秀美的湖泊,还有一側则是漫无边际的沙漠.该国的行政 区划十分特殊,刚好 ...

  3. Python3创建RIDE桌面快捷方式的另一种方法

    今天尝试了一下Python3下安装Robot Framework,但是原来的Python2下创建ride快捷方式的方法都不奏效,启动不了ride.于是,转为VBS脚本的方式来间接创建快捷方式.毕竟,每 ...

  4. hdu 2437(dfs)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2437 思路:只需用一个二维数组记录到达某点时路径长度mod k的最短路径长度,如果余数相同,就更新最小 ...

  5. MySQL------代码1024,can't get hostname for your address解决方法

    1.hosts文件问题 进入C:\Windows\System32\drivers\etc\hosts 查看里面是否包含: # 127.0.0.1 localhost 没有则添加,再重启MySQL服务 ...

  6. Fragment遇到的坑

    Fragment不要通过构造传参,要么就是bundle,要么就通过activity临时存一下,不然debug编译没问题release编译不过

  7. 【BZOJ4832】[Lydsy2017年4月月赛]抵制克苏恩 概率与期望

    [BZOJ4832][Lydsy2017年4月月赛]抵制克苏恩 Description 小Q同学现在沉迷炉石传说不能自拔.他发现一张名为克苏恩的牌很不公平.如果你不玩炉石传说,不必担心,小Q同学会告诉 ...

  8. MySql指令大全(转载)

    1.连接Mysql 格式: mysql -h主机地址 -u用户名 -p用户密码 1.连接到本机上的MYSQL.首先打开DOS窗口,然后进入目录mysql\bin,再键入命令mysql -u root ...

  9. 170407、java基于nio工作方式的socket通信

    客户端代码: /** * */ package com.bobohe.nio; import java.io.BufferedReader; import java.io.IOException; i ...

  10. ITIL信息技术基础架构库

    服务是什么? 服务是向客户提供价值的一种手段,使客户不用承担特定的成本和风险就可以获得所期望的结果 PS:运维工作中需要实时反馈 RACI RACI是一个相对直观的模型,用以明确组织变革过程中的各个角 ...