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

Example 1:

Input: m = 3, n = 2
Output: 3
Explanation:
From the top-left corner, there are a total of 3 ways to reach the bottom-right corner:
1. Right -> Right -> Down
2. Right -> Down -> Right
3. Down -> Right -> Right

Example 2:

Input: m = 7, n = 3 //7列 3行
Output: 28


只能向右或者向下走,求从左上角到右下角一共有多少种走法

C++:
 1 class Solution {
 2 public:
 3     int uniquePaths(int m, int n) {
 4         vector<int> dp(n+1,1) ;
 5         for(int i = 1 ; i < m ; i++){
 6             for(int j = 1 ; j < n ; j++){
 7                 dp[j] = dp[j] + dp[j-1] ;
 8             }
 9         }
10         return dp[n-1] ;
11     }
12 };
原文地址:https://www.cnblogs.com/mengchunchen/p/10266784.html