Leetcode#62. Unique Paths

42人阅读 评论(0) 收藏 举报
分类:

题目描述: m * n 的矩阵, 从左上到右下,只能向下或者向右,一共有多少种走法;

解题思路:典型的动态规划问题

class Solution {
public:
    int uniquePaths(int m, int n) 
    {
        int ways[m][n];
        for(int i = 0; i < m; ++i)
        {
            for(int j = 0; j < n; ++j)
            {
                if(i == 0 && j == 0)
                    ways[0][0] = 1;
                else if(i == 0)
                    ways[0][j] = 1;
                else if(j == 0)
                    ways[i][0] = 1;
                else
                {
                    ways[i][j] = ways[i - 1][j] + ways[i][j - 1];
                }
            }
        }
        return ways[m - 1][n - 1];
    }
};
查看评论

LeetCode#62. Unique Paths

m*n的方格求路径总和
  • u012559634
  • u012559634
  • 2017-04-14 15:02:54
  • 339

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). ...
  • xygy8860
  • xygy8860
  • 2015-07-15 14:23:47
  • 890

LeetCode 62 — Unique Paths(C++ Java Python)

题目:http://oj.leetcode.com/problems/unique-paths/ A robot is located at the top-left corner of a m ...
  • dragon_dream
  • dragon_dream
  • 2014-02-23 22:00:50
  • 2513

LeetCode || Unique Paths

A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). Th...
  • jiadebin890724
  • jiadebin890724
  • 2014-04-09 22:17:47
  • 6991

【LeetCode】Unique Paths 解题报告

【题目】 A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram belo...
  • ljiabin
  • ljiabin
  • 2014-12-08 17:19:53
  • 4186

Unique Paths -- LeetCode

原题链接: http://oj.leetcode.com/problems/unique-paths/  这道题是比较典型的动态规划的题目。模型简单,但是可以考核动态规划的思想。 我们先说说brute...
  • linhuanmars
  • linhuanmars
  • 2014-03-26 04:13:48
  • 10457

62 Unique Paths

题目链接:https://leetcode.com/problems/unique-paths/题目:A robot is located at the top-left corner of a m ...
  • ChilseaSai
  • ChilseaSai
  • 2015-10-14 21:49:20
  • 720

63 Unique Paths II

题目链接:https://leetcode.com/problems/unique-paths-ii/题目:Follow up for "Unique Paths":Now consider if s...
  • ChilseaSai
  • ChilseaSai
  • 2015-10-17 15:31:45
  • 755

[LeetCode][Java] Unique Paths II

题目: Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How...
  • Evan123mg
  • Evan123mg
  • 2015-07-17 09:59:08
  • 807

LeetCode -- Unique Paths II

LeetCode -- Unique Paths II
  • csharp25
  • csharp25
  • 2015-12-01 09:45:52
  • 545
    个人资料
    持之以恒
    等级:
    访问量: 3万+
    积分: 2118
    排名: 2万+