题意:给你n个人,从中取出若干个分成两个子集,不能为空,一个子集给另一个送礼物,问有多少种组合。
当n=5是:第一个子集从5个中选取一个,第二个就可以从4个中选1个(或者2个,3个,4个);
第一个子集从5个中选取两个,第二个就可以从3个中选1个(或者2个,3个);
第一个子集从5个中选取三个,第二个就可以从2个中选1个(或者2个);
第一个子集从5个中选取四个,第二个就可以从4个中选1个
所以可推出∑ni=2Cin∗(2n-i −1),
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 200010
#define mod 1000000009
#define LL long long
using namespace std;
LL f[N],s[N];
int nn;
LL pow_quick(LL n,LL m)
{
LL ans=1;
while(m)
{
if(m&1)
ans=ans*n%mod;
m>>=1;
n=n*n%mod;
}
return ans;
}
LL C(int n,int m)
{
return f[n]*pow_quick(f[m],mod-2)%mod*pow_quick(f[n-m],mod-2)%mod; //逆元 a*a^(p-2) ≡ 1 (mod p)。
}
int main()
{
scanf("%d",&nn);
s[0]=1; f[0]=1;
for(int i=1;i<=nn;i++)
{
f[i]=f[i-1]*i%mod;
s[i]=s[i-1]*2%mod;
}
LL sum=0;
for(int i=1;i<nn;i++)
sum+=C(nn,i)*(s[nn-i]-1)%mod;
printf("%lld\n",sum%mod);
return 0;
}