# bzoj2839: 集合计数

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>

using namespace std;
typedef long long LL;
const int maxn=1e6+100;
const LL mod=1e9+7;
LL quick_pow(LL A,LL p,LL mo)
{
LL ret=1;
while(p!=0)
{
if(p%2==1)ret=ret*A%mo;
A=A*A%mo;p/=2;
}
return ret;
}

//---------------------------def----------------------------------------------

LL fac[maxn],fac_inv[maxn];
LL C(int n,int m){return fac[n]*fac_inv[m]%mod*fac_inv[n-m]%mod;}

LL g[maxn],b[maxn];
void solve(int n)
{
fac[0]=1;fac_inv[0]=1;
for(int i=1;i<=n;i++)fac[i]=fac[i-1]*i%mod;

fac_inv[n]=quick_pow(fac[n],mod-2,mod);
for(int i=n-1;i>=1;i--)fac_inv[i]=fac_inv[i+1]*(i+1)%mod;

//......init......

b[n]=2;
for(int i=n-1;i>=0;i--)b[i]=b[i+1]*b[i+1]%mod;
for(int i=0;i<=n;i++)
g[i]=C(n,i)*(b[i]-1)%mod;
}

//---------------------------prepare----------------------------------------------

int main()
{
//    freopen("a.in","r",stdin);
//    freopen("a.out","w",stdout);
int n,k;
scanf("%d%d",&n,&k);
solve(n);
LL fk=0;
for(int i=k;i<=n;i++)
fk=(fk+(((i-k)%2==0)?1:-1)*C(i,k)*
g[i])%mod;
printf("%lld\n",(fk+mod)%mod);

return 0;
}

pain and happy in the cruel world.
posted @ 2019-01-26 10:38  AKCqhzdy  阅读(106)  评论(0编辑  收藏  举报