# 「BZOJ2839」集合计数

### 「BZOJ2839」集合计数

$b_k=\binom{n}{k}(2^{2^{n-k}}-1)$

$b_k=\sum_{i=k}^n \binom i k a_i$

$f(k)=\sum_{i=k}^n \binom i k g(i) \iff g(k)=\sum_{i=k}^n (-1)^{i-k} \binom i k f(i)$

$f(n)=\sum_{i=k}^n \binom n i g(i) \iff g(n)=\sum_{i=k}^n (-1)^{n-i}\binom n i f(i)$

$a_k=\sum_{i=k}^n (-1)^{i-k}\binom i k \binom n k(2^{2^{n-k}}-1)$

$\texttt{Code:}$

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll p=1e9+7;
const ll maxn=1e6+5;
ll ksm(ll a,ll b,ll p){
ll ans=1;
for(;b;b>>=1,a=1ll*a*a%p)
if(b&1) ans=1ll*ans*a%p;
return ans;
}
ll fac[maxn],inv[maxn];
ll C(ll n,ll m){
if(n<m) return 0;
return 1ll*fac[n]*inv[m]%p*inv[n-m]%p;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
ll n,k;
cin>>n>>k;
fac[0]=1;
for(ll i=1;i<=n;++i) fac[i]=1ll*fac[i-1]*i%p;
inv[n]=ksm(fac[n],p-2,p);
for(ll i=n-1;i>=0;--i) inv[i]=1ll*inv[i+1]*(i+1)%p;
ll ans=0;
for(ll i=k;i<=n;++i){
ans=(ans+1ll*((i-k)&1?(-1):(1))*(C(i,k)*C(n,i)%p*(ksm(2,ksm(2,n-i,p-1),p)%p-1+p))%p+p)%p;
}
cout<<ans<<'\n';
return 0;
}



posted @ 2019-10-20 11:41  Henry__Huang  阅读(242)  评论(0编辑  收藏  举报