Nescafe41 ProblemA 异化多肽 多项式求逆

题目大意:、
我不是图片描述
思路:
搞出 C 的生成函数F(x),那么:
长度为 1 的答案为F(x)
长度为 2 的答案为F2(x)

故最终的答案为
F(x)+F2(x)+F3(x)+...
= 1F+(x)1F(x)
= 11F(x)
然后就是多项式求逆了= =
跪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)了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值