Leetcode62.Unique Paths不同路径
一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为“Start” )。
机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角(在下图中标记为“Finish”)。
问总共有多少条不同的路径?

例如,上图是一个7 x 3 的网格。有多少可能的路径?
说明:m 和 n 的值均不超过 100。
示例 1:
输入: m = 3, n = 2 输出: 3 解释: 从左上角开始,总共有 3 条路径可以到达右下角。 1. 向右 -> 向右 -> 向下 2. 向右 -> 向下 -> 向右 3. 向下 -> 向右 -> 向右
示例 2:
输入: m = 7, n = 3 输出: 28
当i == 0或者 j == 0的时候,机器人只有一种走法。
其他时候,机器人可以从[i][j - 1]或者[i - 1][j]的地方走来
class Solution {
public:
int uniquePaths(int m, int n)
{
vector<vector<int> > dp(m, vector<int>(n, 0));
for(int i = 0; i < m; i++)
{
for(int j = 0; j < n; j++)
{
if(i == 0)
dp[i][j] = 1;
else if(j == 0)
dp[i][j] = 1;
else
dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
}
}
return dp[m - 1][n - 1];
}
};
Leetcode62.Unique Paths不同路径的更多相关文章
- [Leetcode] unique paths 独特路径
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...
- 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). ...
- [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 ...
- leetcode-62. Unique Paths · DP + vector
题面 A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). ...
- [LeetCode62]Unique Paths
题目: A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). ...
- [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 ...
- leetcode62—Unique Paths
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...
- 062 Unique Paths 不同路径
机器人位于一个 m x n 网格的左上角, 在下图中标记为“Start” (开始).机器人每次只能向下或者向右移动一步.机器人试图达到网格的右下角,在下图中标记为“Finish”(结束).问有多少条不 ...
- 62. Unique Paths不同路径
网址:https://leetcode.com/problems/unique-paths/ 第一思路是动态规划 通过观察,每一个格子的路线数等于相邻的左方格子的路线数加上上方格子的路线数 于是我们就 ...
随机推荐
- 深入了解组件- -- 动态组件 & 异步组件
gitHub地址:https://github.com/huangpna/vue_learn/example里面的lesson11 一 在动态组件上使用keep-alive 在这之前我们已经有学习过用 ...
- LA4794 Sharing Chocolate
传送门 记忆化搜索. 在下觉得sxy大佬的代码写得相当好,通篇的骚操作(因为我都不会呀),%%% 学到了 预处理每个状态的值.以前的我都是zz地枚举每一位.. for(int i=1;i<(1& ...
- 群晖的moments套件 发生未知错误
一次了,哎 也不知道什么原因引起的 只能再搞一遍 先把homes文件夹数据弄走,免得弄丢 然后卸载momemts,删除数据库 还有其他人遇到这个情况http://www.gebi1.com/threa ...
- java mat复制问题
意外的发现 org.opencv.core.Mat projectionMat = mat ;//曲线救国,获取同样一个mat projectionMat.setTo());//然后再把颜色换成白色 ...
- VC++1.5太伟大了
功能样样俱全,一点不比现在的VS系列差 VC++1.5全貌,虽然很古老,但是已经可以了. 新建的文档试图,多文档工程,很像样 文档试图,单文档工程,已经非常像样了,和记事本差不多了 这是资源编辑器,寒 ...
- python-web-下载所有xkcd漫画
下载所有xkcd漫画 # downloads every single xkcd comic import requests,os,bs4 url='http://xkcd.com' # start ...
- 文件内容操作命令 cat、more、less、head、tail、wc、grep 命令详情
文件内容操作命令 cat.more.less.head.tail.wc.grep 命令详情 1) cat命令 用途:显示出文件的全部内容 格式:cat 目标文件 例: ...
- Hackerrank--Prime Sum
题目链接 The problem is quite simple. You're given a number N and a positive integer K. Tell if N can be ...
- IoT: 物联网安全测试经验总结
前言 今年早些时候,我参与了许多关于物联网解决方案的安全测试.主要目标是找出体系结构和解决方案中的漏洞.在这篇文章中,我将讨论一些与物联网解决方案的问题和挑战. 什么是物联网? 在你学习有关IPv6的 ...
- Eclipse 出现select type (? = any character,*= any String,Tz=TimeZone)
在eclipse中想运行project的时候,往往是右键项目名称---->run As --->Java Application 但是会弹出窗口显示select type (? = any ...