组合数C(m,n)模板

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sugarbliss/article/details/85055348

公式递推代码:C(n, m)  = C(n -1, m - 1) + C(n - 1, m)。

void get_c(ll x)
{
    c[0][0] = 1;
    for(int i = 1; i <= x; i++)
    {
        c[i][0] = 1;
        for(int j = 1; j <= i; j++)
        c[i][j] = (c[i-1][j]+c[i-1][j-1])%mod;
    }
}
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 2e3+10;
const ll mod = 998244353;
ll c[maxn][maxn];
void get_c(ll x)
{
    c[0][0] = 1;
    for(int i = 1; i <= x; i++)
    {
        c[i][0] = 1;
        for(int j = 1; j <= i; j++)
        c[i][j] = (c[i-1][j]+c[i-1][j-1])%mod;
    }
}
int main()
{
    ll n;
    cin >> n;
    get_c(n); ll ans;
    ans = c[4][2];
    cout << ans << endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/sugarbliss/article/details/85055348
今日推荐