BZOJ4706 B君的多边形 (超级卡特兰数/施罗德数)

题目

权限题QAQ

题解

超级卡特兰数/施罗德数

CODE

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000005;
const int mod = 1e9 + 7;
int inv[MAXN], f[MAXN], n;
int main () {
    scanf("%d", &n);
    inv[0] = inv[1] = f[0] = f[1] = 1;
    for(int i = 2; i <= n; ++i) inv[i] = 1ll*(mod-mod/i)*inv[mod%i]%mod;
    for(int i = 2; i <= n-2; ++i)
        f[i] = ((6ll*i-3)*f[i-1] - (i-2ll)*f[i-2]) % mod * inv[i+1] % mod;
    printf("%d\n", (f[n-2]+mod)%mod);
}
posted @ 2019-12-14 14:50  _Ark  阅读(207)  评论(0编辑  收藏  举报