1 条题解

  • 0
    @ 2025-10-8 16:50:23

    G32 卡特兰数

    #include <bits/stdc++.h> 
    using namespace std;
    typedef unsigned long long LL;
    int n, m, a[110], b[110];
    LL gcd(LL x, LL y) { if (y == 0) return x; else return gcd(y, x % y); }
    LL cal(LL n, LL m)
    {
        m = min(m, n - m);
        LL s = 1;
        for (int i = 1; i <= m; i++) a[i] = n - i + 1, b[i] = i;
        for (int i = 1; i <= m; i++)
        {
            for (int j = 1; j <= m; j++)
            {
                LL d = gcd(a[i], b[j]);
                a[i] /= d;
                b[j] /= d;
            }
            s *= a[i];
        }
        return s;
    }
    int main()
    {
        int n; scanf("%d", &n);
        LL ans = cal(2 * n, n) / (n + 1);
        printf("%lu", ans);
        return 0;
    }
    
    • 1

    G32*【组合数:Catalan数】卡特兰数(Catalan)

    信息

    ID
    401
    时间
    1000ms
    内存
    128MiB
    难度
    8
    标签
    递交数
    372
    已通过
    66
    上传者