计蒜客 杨辉三角(DP)

杨辉三角

#include <iostream>
#include <string>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cassert>

#define maxn 55
using namespace std;

int n, m;
long long dp[maxn][maxn];
int main()
{
    //freopen("data.in","r",stdin);
    ios::sync_with_stdio(false);

    cin >> n >> m;
    dp[1][1] = 1;
    dp[2][1] = 1;
    dp[2][2] = 1;

    for(int i = 3; i <= n; ++i) {
        for(int j = 1; j <= i; ++j) {
            if(j == 1 || j == i) {
                dp[i][j] = 1;
                continue;
            }

            dp[i][j] = dp[i-1][j-1] + dp[i-1][j];
        }

    }

    cout << dp[n][m] << endl;
    return 0;
}

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