题目:给定一个m*n的矩阵,从头开始,只能往右边和下边走,一次走一格,知道走到最后一个(右下角)为止。总共有多少种走法。

典型的动态规划吧。其实从头走到尾部,和从尾部开始走到头是一样的次数。我们用一个矩阵记录到第一格子的次数,那么可以看到有如下的表:

假设是3*4的矩阵,那么我们要返回的就是10了,每个当前的值是它的左边加上上边

代码如下:

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

leetcode[61] Unique Paths的更多相关文章

  1. LeetCode 63. Unique Paths II不同路径 II (C++/Java)

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

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

  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] 63. Unique Paths II_ Medium tag: Dynamic Programming

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

  5. [Leetcode Week12]Unique Paths II

    Unique Paths II 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/unique-paths-ii/description/ Descrip ...

  6. [Leetcode Week12]Unique Paths

    Unique Paths 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/unique-paths/description/ Description A ...

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

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

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

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

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

随机推荐

  1. IOS经典的书籍推荐

    基础 objective-c基础教程 iphone 开发秘籍 进阶篇 iOS 6编程实战 Objective-C 高级编程:iOS与OS X多线程和内存管理 Effective Objective-C ...

  2. Mapxtreme C#鹰眼地图

    Demo演示程序下载地址: http://pan.baidu.com/s/1jG9gKMM#dir/path=%2F%E4%BA%A7%E5%93%81%2FDemos 找:EagelEyeMap.r ...

  3. 新的学生说说我是如何靠APP发展赢得了亿万

    郝萌主倾心贡献,尊重作者的劳动成果,请勿转载. 假设文章对您有所帮助,欢迎给作者捐赠.支持郝萌主,捐赠数额任意.重在心意^_^ 我要捐赠: 点击捐赠 Cocos2d-X源代码下载:点我传送 14年踏入 ...

  4. SQLServer 2012异常问题(二)--由安装介质引发性能问题

    原文:SQLServer 2012异常问题(二)--由安装介质引发性能问题 问题描述:生产环境一个数据库从SQLSERVER 2008 R2升级到SQLSERVER 2012 ,同时更换硬件,但迁移后 ...

  5. POJ2299 Ultra-QuickSort 【树阵】+【hash】

    Ultra-QuickSort Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 39529   Accepted: 14250 ...

  6. Ubuntu 15.10 x64 安装 Android SDK(转)

    操作系统:Ubuntu 15.10 x64 目标:安装 Android SDK 本文最后更新时间:2015-11-3 安装32位库文件 2013年9月的iPhone 5s是第一款64位手机,而Andr ...

  7. SpringMVC使用FileUpload上传文件

    进口FileUpload和common-io的Jar包 注意:1.Struts2其它方法需要使用的:struts2过滤,将改变reqeust类型,由HttpServletRequest成为MultiP ...

  8. Putty是一个专业的SSH连接客户端

    http://www.putty.ws/PuTTY-LinuxVPS Putty是一个专业的SSH连接客户端,当然可以用来连接Linux操作系统的VPS.下文是Putty连接工具的使用方法与详细教程, ...

  9. Ubuntu Server 14.04 LTS(64bit)已安装 weblogic Server 12c(12.1.3) Zip Distribution

    这里说的对Ubuntu Server 14.04 LTS(64bit)已安装weblogic Server 12c(12.1.3) Zip Distribution遇到的问题.至于Windows什么好 ...

  10. shell 中用管道模拟多线程

    shell 中用管道模拟多线程 这里以两个例子来对比多线程和单进程 单线程的例子 # config.txt在这个例子和多线程的例子中都会用到 [root@ns_10.2.1.242 test]$ ca ...