zoukankan      html  css  js  c++  java
  • 【洛谷P4233】— 射命丸文的笔记(竞赛图+多项式求逆)

    传送门

    考虑强连通竞赛图哈密顿回路总数很好求
    (n1)!2(n2)n(n-1)!2^{{nchoose 2}-n}

    现在问题是求强连通竞赛图数
    fif_iii个点的图数
    fn=2(n2)i=1n1fi(ni)2(ni2)f_n=2^{{nchoose 2}}-sum_{i=1}^{n-1}f_i{nchoose i}2^{{n-ichoose 2}}
    即枚举拓扑序最小的强连通竞赛子图,剩下部分的随便连

    发现这个可以多项式求逆

    注意特判n=1,2n=1,2

    #include<bits/stdc++.h>
    using namespace std;
    const int RLEN=1<<20|1;
    inline char gc(){
        static char ibuf[RLEN],*ib,*ob;
        (ob==ib)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
        return (ob==ib)?EOF:*ib++;
    }
    #define gc getchar
    inline int read(){
        char ch=gc();
        int res=0,f=1;
        while(!isdigit(ch))f^=ch=='-',ch=gc();
        while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
        return f?res:-res;
    }
    #define ll long long
    #define re register
    #define pii pair<int,int>
    #define fi first
    #define se second
    #define pb push_back
    #define cs const
    #define bg begin
    #define poly vector<int>
    template<class T>inline void chemx(T &a,T b){a<b?a=b:0;}
    template<class T>inline void chemn(T &a,T b){a>b?a=b:0;}
    cs int mod=998244353,G=3;
    inline int add(int a,int b){a+=b-mod;return a+(a>>31&mod);}
    inline void Add(int &a,int b){a+=b-mod;a+=a>>31&mod;}
    inline int dec(int a,int b){a-=b;return a+(a>>31&mod);}
    inline void Dec(int &a,int b){a-=b;a+=a>>31&mod;}
    inline int mul(int a,int b){return 1ll*a*b%mod;}
    inline void Mul(int &a,int b){a=1ll*a*b%mod;}
    inline int ksm(int a,int b,int res=1){for(;b;b>>=1,Mul(a,a))(b&1)&&(Mul(res,a),1);return res;}
    inline int Inv(int x){return ksm(x,mod-2);};
    cs int C=18;
    poly w[C+1];
    inline void init_w(){
    	for(int i=1;i<=C;i++)w[i].resize(1<<(i-1));
    	int wn=ksm(G,(mod-1)/(1<<C));w[C][0]=1;
    	for(int i=1;i<(1<<(C-1));i++)w[C][i]=mul(w[C][i-1],wn);
    	for(int i=C-1;i;i--)
    	for(int j=0;j<(1<<(i-1));j++)w[i][j]=w[i+1][j<<1];
    }
    cs int N=100005;
    int fac[N],ifac[N],inv[N];
    inline void init_inv(){
    	fac[0]=ifac[0]=inv[0]=inv[1]=1;
    	for(int i=1;i<N;i++)fac[i]=mul(fac[i-1],i);
    	ifac[N-1]=Inv(fac[N-1]);
    	for(int i=N-2;i;i--)ifac[i]=mul(ifac[i+1],i+1);
    	for(int i=2;i<N;i++)inv[i]=mul(mod-mod/i,inv[mod%i]);
    }
    int rev[(1<<C)|5];
    inline void init_rev(int lim){
    	for(int i=0;i<lim;i++)rev[i]=(rev[i>>1]>>1)|((i&1)*(lim>>1));
    }
    inline void ntt(poly &f,int lim,int kd){
    	for(int i=0;i<lim;i++)if(i>rev[i])swap(f[i],f[rev[i]]);
    	for(int mid=1,l=1,a0,a1;mid<lim;mid<<=1,l++)
    	for(int i=0;i<lim;i+=(mid<<1))
    	for(int j=0;j<mid;j++)
    	a0=f[i+j],a1=mul(w[l][j],f[i+j+mid]),f[i+j]=add(a0,a1),f[i+j+mid]=dec(a0,a1);
    	if(kd==-1){
    		reverse(f.bg()+1,f.bg()+lim);
    		for(int i=0,iv=Inv(lim);i<lim;i++)Mul(f[i],iv);
    	}
    }
    inline poly operator *(poly a,poly b){
    	int deg=a.size()-b.size()+1,lim=1;
    	if(deg<=32){
    		poly c(deg,0);
    		for(int i=0;i<a.size();i++)
    		for(int j=0;j<b.size();j++)
    		Add(c[i+j],mul(a[i],b[j]));
    		return c;
    	}
    	while(lim<deg)lim<<=1;
    	init_rev(lim);
    	a.resize(lim),ntt(a,lim,1);
    	b.resize(lim),ntt(b,lim,1);
    	for(int i=0;i<lim;i++)Mul(a[i],b[i]);
    	ntt(a,lim,-1),a.resize(deg);
    	return a;
    }
    inline poly Inv(poly a,int deg){
    	poly b(1,Inv(a[0])),c;
    	for(int lim=4;lim<(deg<<2);lim<<=1){
    		c=a,c.resize(lim>>1);
    		init_rev(lim);
    		b.resize(lim),ntt(b,lim,1);
    		c.resize(lim),ntt(c,lim,1);
    		for(int i=0;i<lim;i++)Mul(b[i],dec(2,mul(b[i],c[i])));
    		ntt(b,lim,-1),b.resize(lim>>1);
    	}
    	b.resize(deg);return b;
    }
    poly f,g;
    int n;
    int main(){
    	init_w();
    	init_inv();
    	n=read();
    	g.resize(n+1),f.resize(n+1);
    	for(int i=0;i<=n;i++)g[i]=mul(ksm(2,(1ll*i*(i-1)/2)%(mod-1)),ifac[i]);
    	g=Inv(g,n+1);
    	for(int i=0;i<=n;i++)f[i]=dec(0,g[i]);
    	Add(f[0],1);
    	for(int i=0;i<=n;i++)Mul(f[i],fac[i]);
    	if(n>=1)cout<<1<<'
    ';
    	if(n>=2)cout<<-1<<'
    ';
    	for(int i=3;i<=n;i++)
    	cout<<mul(mul(fac[i-1],ksm(2,(1ll*i*(i-1)/2-i)%(mod-1))),Inv(f[i]))<<'
    ';
    }
    
  • 相关阅读:
    11.SpringBoot学习(十一)——JDBC之 Spring Boot JdbcTemplate
    10.SpringBoot学习(十)——JDBC之 Spring Boot Jpa
    9.SpringBoot学习(九)——Spring Boot Admin使用
    8.SpringBoot学习(八)——Spring Boot Actuator监控
    7.SpringBoot学习(七)——Spring Boot Email发送邮件
    5.Gradle组件说明
    3.Gradle构建Java项目
    6.Gradle多模块项目
    flash解析json格式
    java窗体与Flash交互
  • 原文地址:https://www.cnblogs.com/stargazer-cyk/p/12328370.html
Copyright © 2011-2022 走看看