• CTS 2019 Pearl


    CTS2019 Pearl

    每种颜色有奇偶两种情况,只有偶数和只有奇数个,其对应的的指数型生成函数分别为 (frac{e^x+e^{-x}}2,frac{e^x-e^{-x}}2)

    考虑选出现奇数次的颜色受一定限制,所以本质上就是要求这个东西

    [frac{n!}{2^D}sum_{i=0}^{n-2m} [(e^x+e^{-x})+y(e^x-e^{-x})]^D[x^ny^i] \ =frac{n!}{2^D}sum_{i=0}^{n-2m} [(1+y)e^x+(1-y)e^{-x}]^D[x^ny^i] \ =frac{n!}{2^D}sum_{i=0}^{n-2m}sum_{k=0}^D inom{D}{k}(1+y)^k(1-y)^{D-k}e^{(2k-D)x} [x^ny^i] \ =frac1{2^D}sum_{i=0}^{n-2m}sum_{k=0}^D (2k-D)^Dinom{D}{k}(1+y)^k(1-y)^{D-k} [y^i] \ =frac1{2^D}sum_{k=0}^D (2k-D)^Dinom{D}{k} sum_{i=0}^{n-2m} (1+y)^k(1-y)^{D-k} [y^i] \ ------------------------- \ F(k,D)=sum_{i=0}^{n-2m} (1+y)^k(1-y)^{D-k} [y^i] \ =sum_{i=0}^{n-2m} (2-(1-y))(1+y)^{k-1}(1-y)^{D-k} [y^i] \ =sum_{i=0}^{n-2m} 2(1+y)^{k-1}(1-y)^{D-k} [y^i] -sum_{i=0}^{n-2m}(1+y)^{k-1}(1-y)^{D-k+1} [y^i] \ =2F(k-1,D-1)-F(k-1,D)\ ------------------------- \ G_i=F(0,i) = sum_{j=0}^{n-2m} (1-y)^i[y^j] = sum_{j=0}^{n-2m} (-1)^jinom{i}{j}\ = sum_{j=0}^{n-2m} (-1)^j(inom{i-1}{j-1}+inom{i-1}{j})\ = sum_{j=0}^{n-2m} (-1)^jinom{i-1}{j}-sum_{j=0}^{n-2m-1}(-1)^jinom{i-1}{j}\ = (-1)^{n-2m}inom{i-1}{n-2m} \ ------------------------- \ F(k,D)=sum_{i=0}^D F(0,i)2^{D-i}(-1)^{k-(D-i)}inom{k}{D-i} \ =k!sum_{i=0}^D frac{G_i(-1)^{k-(D-i)}2^{D-i}}{(D-i)!(k-(D-i))!} \ =k!sum_{i=0}^D frac{G_{D-i}(-1)^{k-i}2^i}{i!(k-i)!} \ ------------------------- \ T_i=frac{G_{D-i}2^i}{i!} , H_i=frac{(-1)^i}{i!} , F_i=(H*T)_i imes i!\ Ans=frac1{2^D}sum_{k=0}^D (2k-D)^Dinom{D}{k}F_k \ ]

    一次卷积即可,注意要定义 (G_0=1)

    式子没有仔细检查,有错见谅qwq

    #include<bits/stdc++.h>
    #define LL long long
    using namespace std;
    int read(){
    	int nm=0,fh=1; char cw=getchar();
    	for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
    	for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
    	return nm*fh;
    }
    #define pii pair<int,int>
    #define mp make_pair
    #define mod 998244353
    #define M 600010
    #define inv3 332748118
    #define inv2 499122177
    namespace CALC{
    	inline int add(int x,int y){x+=y;return (x>=mod)?(x-mod):x;}
    	inline int mns(int x,int y){x-=y;return (x<0)?(x+mod):x;}
    	inline int mul(LL x,LL y){return (LL)x*(LL)y%mod;}
    	inline void upd(int &x,int y){x+=y;(x>=mod)?(x-=mod):0;}
    	inline void dec(int &x,int y){x-=y;(x<0)?(x+=mod):0;}
    	inline int qpow(int x,int sq){
    		int res=1;
    		for(;sq;sq>>=1,x=mul(x,x)) if(sq&1) res=mul(res,x);
    		return res;
    	}
    }using namespace CALC;
    int n,m,D,od[M],fac[M+2],ifac[M+2],G[M],H[M],T[M],F[M];
    inline int C(int tot,int tk){return (tk<0||tot<tk)?0:mul(fac[tot],mul(ifac[tk],ifac[tot-tk]));}
    inline void NTT(int *x,int len,int kd){
    	for(int i=1;i<len;i++) if(i<od[i]) swap(x[i],x[od[i]]);
    	for(int tt=1;tt<len;tt<<=1){
    		int wn=qpow(kd>0?3:inv3,(mod-1)/(tt<<1));
    		for(int st=0,now=1;st<len;st+=(tt<<1),now=1){
    			for(int pos=st;pos<st+tt;pos++,now=mul(now,wn)){
    				int t1=x[pos],t2=mul(now,x[pos+tt]);
    				x[pos]=add(t1,t2),x[pos+tt]=mns(t1,t2);
    			}
    		}
    	} if(kd>0) return; int rv=qpow(len,mod-2);
    	for(int i=0;i<len;i++) x[i]=mul(x[i],rv);
    }
    int main(){
    	D=read(),n=read(),m=read();
    	if(n-m-m>=D){printf("%d
    ",qpow(D,n)); return 0;}
    	if(n<m+m){puts("0"); return 0;} fac[0]=1;
    	for(int i=1;i<=M;i++) fac[i]=mul(fac[i-1],i); ifac[M]=qpow(fac[M],mod-2);
    	for(int i=M;i>=1;i--) ifac[i-1]=mul(ifac[i],i); int len=1,nw=-1,ans=0;
    	while(len<=D+D) len<<=1,nw++;
    	for(int i=1;i<len;i++) od[i]=(od[i>>1]>>1)|((i&1)<<nw);
    	for(int i=1;i<=D;i++) G[i]=C(i-1,n-m-m); G[0]=1;
    	if(n&1){for(int i=1;i<=D;i++) G[i]=mns(0,G[i]);}
    	for(int i=0;i<=D;i++) H[i]=(i&1)?mns(0,ifac[i]):ifac[i];
    	for(int i=0;i<=D;i++) T[i]=mul(G[D-i],mul(ifac[i],qpow(2,i)));
    	NTT(T,len,1),NTT(H,len,1);
    	for(int i=0;i<len;i++) F[i]=mul(T[i],H[i]); NTT(F,len,-1);
    	for(int i=0;i<=D;i++) F[i]=mul(F[i],fac[i]); 
    	for(int i=0;i<=D;i++) upd(ans,mul(qpow(mns(i+i,D),n),mul(C(D,i),F[i])));
    	printf("%d
    ",mul(qpow(inv2,D),ans)); return 0;
    }
    
  • 相关阅读:
    标定相关-一些资源
    论文基础-5几何知识
    论文基础-3微积分
    h5页面 判断网页是否由微信或qq内置浏览器打开
    Html5 页面后退并刷新
    h5 页面下拉刷新
    绑定点击事件 传参
    公众号做分享功能
    清微信缓存
    手机端适配
  • 原文地址:https://www.cnblogs.com/OYJason/p/10908462.html
Copyright © 2020-2023  润新知