牛客OI周赛4-提高组 B 最后的晚餐(dinner)
思路:
容斥
求 ∑(-1)^i * C(n, i) * 2^i * (2n-i-1)!
这道题卡常数
#pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pi acos(-1.0) #define LL long long //#define mp make_pair #define pb push_back #define ls rt<<1, l, m #define rs rt<<1|1, m+1, r #define ULL unsigned LL #define pll pair<LL, LL> #define pli pair<LL, int> #define pii pair<int, int> #define piii pair<pii, int> #define mem(a, b) memset(a, b, sizeof(a)) #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout); //head const LL MOD = 1e9 + 7; const int N = 3e7 + 5; int f[N], inv[N]; LL q_pow(LL n, LL k) { LL ans = 1; while(k) { if(k&1) ans = (ans * n) % MOD; n = (n * n) % MOD; k >>= 1; } return ans; } int main() { int n; scanf("%d", &n); if(n == 1) return 0*puts("0"); LL ans = 0; int fac = 1, pw = q_pow(2, n), c = 1; f[0] = 1; for (int i = 1; i <= n; i++) f[i] = (1LL * f[i-1] * i) % MOD; inv[n] = q_pow(f[n], MOD-2) % MOD; for (int i = n-1; i >= 0; i--) inv[i] = (1LL * inv[i+1]*(i+1)) % MOD; fac = f[n-1]; for (int i = n; i >= 0; i--) { (ans += ((i%2) ? -1 : 1) * 1LL * inv[i] % MOD * inv[n-i] % MOD * pw % MOD * fac) %= MOD; fac = (1LL * fac * (2*n - i)) % MOD; pw = (1LL * pw * inv[2]) % MOD; } ans = (ans + MOD) % MOD; ans = ans * f[n] % MOD; printf("%lld\n", ans); return 0; }