20.12.9 leetcode62组合

题目链接:https://leetcode-cn.com/problems/unique-paths/

题意:有一个m*n的地图,问从左上角到右下角有多少中路径。

分析:直接用组合,就是C(m+n-2,n)的值。

class Solution {
public:
    int uniquePaths(int m, int n) {
        long long ans = 1;
        for (int x = n, y = 1; y < m; ++x, ++y) {
            ans = ans * x / y;
        }
        return ans;
    }
};
原文地址:https://www.cnblogs.com/qingjiuling/p/14108179.html