计蒜客 杨辉三角(DP)

杨辉三角

#include 
#include 
#include 
#include 
#include 
#include 
#include 

#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;
}

你可能感兴趣的:(DP)