# bzoj2839 集合计数

[没有嘟嘟嘟，权限题]

$dp[i]$的时候可以从后往前推，就能处理$2 ^ {2 ^ {n - i}}$这东西了。
（别忘了有$k = 0$的情况）

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
#include<assert.h>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define In inline
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 1e6 + 5;
const ll mod = 1e9 + 7;
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
if(last == '-') ans = -ans;
return ans;
}
In void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
}
In void MYFILE()
{
#ifndef mrclr
freopen("ha.in", "r", stdin);
freopen("ha.out", "w", stdout);
#endif
}

int n, K;
ll fac[maxn], inv[maxn];

In ll inc(ll a, ll b) {return a + b < mod ? a + b : a + b - mod;}
In ll C(int n, int m)
{
if(n < m) return 0;
return fac[n] * inv[m] % mod * inv[n - m] % mod;
}
In ll quickpow(ll a, ll b)
{
ll ret = 1;
for(; b; b >>= 1, a = a * a % mod)
if(b & 1) ret = ret * a % mod;
return ret;
}

In void init()
{
fac[0] = inv[0] = 1;
for(int i = 1; i < maxn; ++i) fac[i] = fac[i - 1] * i % mod;
inv[maxn - 1] = quickpow(fac[maxn - 1], mod - 2);
for(int i = maxn - 2; i; --i) inv[i] = inv[i + 1] * (i + 1) % mod;
}

ll dp[maxn];

int main()
{
MYFILE();
init();
ll tp = 2;
for(int i = n; i >= 0; --i)
{
dp[i] = C(n, i) * (tp - 1) % mod;
tp = tp * tp % mod;
}
ll ans = 0;
for(int i = K, t = 1; i <= n; ++i, t *= (-1))
{
ll tp = C(i, K) * dp[i] % mod * t;
if(tp < 0) tp += mod;
ans = inc(ans, tp);
}
write(ans), enter;
return 0;
}

posted @ 2019-06-06 20:30  mrclr  阅读(169)  评论(0编辑  收藏  举报