题目大意:、
思路:
搞出
长度为
长度为
…
故最终的答案为
=
=
然后就是多项式求逆了= =
跪picks大毒瘤
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define M (263000<<1)
#define P 1005060097
#define G 5
using namespace std;
int n,m,l;
int a[M],b[M];
long long Quick_Power(long long x,long long y)
{
long long re=1;
while(y)
{
if(y&1) (re*=x)%=P;
(x*=x)%=P; y>>=1;
}
return re;
}
void NTT(int a[],int n,int type)
{
static int temp[M];
int i;
if(n==1) return ;
for(i=0;i<n;i+=2)
temp[i>>1]=a[i],temp[i+n>>1]=a[i+1];
memcpy(a,temp,sizeof(a[0])*n);
int *l=a,*r=a+(n>>1);
NTT(l,n>>1,type);
NTT(r,n>>1,type);
long long w=Quick_Power(G,(long long)(P-1)/n*type%(P-1)),wn=1;
for(i=0;i<n>>1;i++,(wn*=w)%=P)
temp[i]=(l[i]+wn*r[i])%P,temp[i+(n>>1)]=(l[i]-wn*r[i]%P+P)%P;
memcpy(a,temp,sizeof(a[0])*n);
}
void Get_Inv(int a[],int b[],int n)
{
static int temp[M];
int i;
if(n==1)
{
b[0]=Quick_Power(a[0],P-2);
return ;
}
Get_Inv(a,b,n>>1);
memcpy(temp,a,sizeof(a[0])*n);
NTT(temp,n<<1,1);
NTT(b,n<<1,1);
for(i=0;i<n<<1;i++)
temp[i]=(long long)b[i]*(2-(long long)temp[i]*b[i]%P+P)%P;
NTT(temp,n<<1,P-2);
long long inv=Quick_Power(n<<1,P-2);
for(i=0;i<n;i++)
b[i]=temp[i]*inv%P;
memset(b+n,0,sizeof(a[0])*n);
}
int main()
{
freopen("polypeptide.in","r",stdin);
freopen("polypeptide.out","w",stdout);
int i,x;
cin>>n>>m;
for(a[0]=1,i=1;i<=m;i++)
{
scanf("%d",&x);
if(x<=n) a[x]--;
if(a[x]<0) a[x]+=P;
}
for(l=1;l<=n+n+3;l<<=1);
Get_Inv(a,b,l);
cout<<b[n]<<endl;
return 0;
}
可惜电(chang)脑(shu)太(bao)慢(zha)了。
原文地址:http://blog.csdn.net/popoqqq/article/details/45335371