# bzoj2339[HNOI2011]卡农 dp+容斥

#### 2339: [HNOI2011]卡农

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 842  Solved: 510
[Submit][Status][Discuss]

#### Description

1.最后确定的集合为空,这种情况的方案数=f[i-1]
2.最后确定的集合和之前确定的集合重复,因为有重复,所以删去这两个重复的集合,

ans就可以计算了

http://blog.csdn.net/dflasher/article/details/51615325

#include<iostream>
#include<cstdio>
#define N 1000010
#define P 100000007
using namespace std;
long long n,m,p[N],f[N],temp;
long long power(long long a,long long b)
{
long long ans(1);
for(long long i=b;i;i>>=1,(a*=a)%=P) if(i&1)(ans*=a)%=P;
return ans;
}
void pre()
{
p[0]=1;
for (long long i=1;i<=m;i++) p[i]=(p[i-1]*((temp-i+1+P)%P))%P;
}
int main()
{
scanf("%lld%lld",&n,&m);
temp=power(2,n);temp--;
if (temp<0) temp+=P;
pre();
for (long long i=3;i<=m;i++)
f[i]=((p[i-1]-f[i-1]-f[i-2]*(i-1)%P*(temp-(i-2))%P)+P)%P;
temp=1;
for (long long i=1;i<=m;i++) (temp*=i)%=P;
(f[m]*=power(temp,P-2))%=P;
cout<<f[m];
}

If you live in the echo,
your heart never beats as loud.

posted @ 2017-12-12 08:53  _wsy  阅读(143)  评论(0编辑  收藏  举报