题意:

  给出一个m*n的矩阵,robot要从[1][1]走到[m][n],每次只能往下/右走,问有多少种走法?

思路:

  DP的经典问题。先将[1][1]设为1,然后两种走法就是分别用[i][j]去更新[i+1][j]和[i][j+1]。

  观察一下数组的更新次序就可以知道,这很像完全背包的更新方式,那么就可以用一维数组就行了。更新方式从左到右就行了。

  由于这是DP题,就没有必要去研究数学公式了(涉及等差数列求和)。

 class Solution {
public:
int uniquePaths(int m, int n) {
vector<int> p(n,);
for(int i=; i<m; i++)
for(int j=; j+<n; j++)
p[j+]+=p[j];
return p[n-];
}
};

AC代码

LeetCode Unique Paths (简单DP)的更多相关文章

  1. LeetCode: Unique Paths II 解题报告

    Unique Paths II Total Accepted: 31019 Total Submissions: 110866My Submissions Question Solution  Fol ...

  2. [LeetCode] Unique Paths && Unique Paths II && Minimum Path Sum (动态规划之 Matrix DP )

    Unique Paths https://oj.leetcode.com/problems/unique-paths/ A robot is located at the top-left corne ...

  3. [LeetCode] Unique Paths II 不同的路径之二

    Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...

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

  5. Leetcode Unique Paths II

    Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...

  6. 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 ...

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

  8. [leetcode]Unique Paths @ Python

    原题地址:https://oj.leetcode.com/problems/unique-paths/ 题意: A robot is located at the top-left corner of ...

  9. [Leetcode] unique paths ii 独特路径

    Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...

  10. LeetCode:Unique Paths I II

    Unique Paths A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagra ...

随机推荐

  1. PMP 项目管理

    1.什么是项目管理   项目管理就是把各种知识,技能,工具,技术应用于项目活动,来满足项目的需求.这个是从技术方面来说的.其实在项目管理的技术 层面背后,还有理念层面的内容.学习项目管理,除了学习技术 ...

  2. 所思所想 关于asp.net界面业务分离

    1.体会:使用ASP.NET控件来做前段是有很大的局限性的 2.使用拼接HTML的方式来写代码虽然不符合模式,但是有很大的灵活性 3.如果使用拼接字符串的方式来生成前台的代码,使用NV的话完全可以实现 ...

  3. FusionCharts ajax 调用方式

    方式一:setJSONUrl function initChart() {                    var myChart = new FusionCharts("Fusion ...

  4. spring mvc读取url变量

    @RequestMapping(value="/{id}/{name}", method=RequestMethod.GET) public ModelAndView getUrl ...

  5. HDU 4893 Wow! Such Sequence!(2014 Multi-University Training Contest 3)

    题意: 有三种操作: 1 x y: 表示给x位置加上y 2 x y:查询[x,y]的区间和 3 x y:将 [x,y] 区间上的数变为最接近的 Fibonacci. 思路: 1 操作按正常单调更新,区 ...

  6. C++-bool的值

    /////////////////////////////////////////////////////////////////////////////// // // FileName : boo ...

  7. Opencv的基础结构与内容

  8. SPOJ COT2 树上找路径上不同值的个数

    题目大意 给出多个询问u , v , 求出u-v路径上点权值不同的个数 开始做的是COT1,用主席树写过了,理解起来不难 很高兴的跑去做第二道,完全跟普通数组区间求k个不同有很大区别,完全没思路 膜拜 ...

  9. UIKit-3347.44.2/UICollectionView.m:3443

    Assertion failure in -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewC ...

  10. linux命令每日一练习-pwd,cd

    pwd显示当前路径. pwd -P没能明白什么意思, cd 进入目录 cd ..返回上级目录