排列组合与杨辉三角类比运算

                                             1
                                           1  1
                                          1  2  1
                                        1  3  3  1
                                      1  4  6  4  1
                                   

此杨辉三角计算公式: a[i][j] = a[i-1][j-1]+a[i-1][j];

与排列组合中:Cij​   = Ci1j+Ci1j1

具有类似之处,

来一道应用题,

假设要从一个 n 行 m 列的格子的左上角走到右下角,每次只能向右走一步,或者向下走一步,那么有多少种走法?

这道题其实也有动态的身影,

输入格式,(1=<n<=3,3<m<=1000000000)


#include <iostream>

using namespace std;


int main(){
    long long n,m;
    cin>>n>>m;
    if(n == 1){
        cout<<1<<endl;
        return 0;
    }
    long long one = 1;
    long long  two = 0;
    long long three = 0;
    if(n == 2)
    for(int i = 1;i <= m;i ++){
        two = two + one;
    }
    if(n == 3)
    for(int i = 1;i <=m ;i ++){
        two = two + one;
        three = three + two;
    }


    if(n == 2)
        cout<<two<<endl;
    if(n == 3)
        cout<<three<<endl;

    return 0;
}


    原文作者:杨辉三角问题
    原文地址: https://blog.csdn.net/pack__pack/article/details/71154358
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞