当前位置:网站首页>20200727 T2 small w playing game [generating function (binomial inversion technique)]
20200727 T2 small w playing game [generating function (binomial inversion technique)]
2022-06-11 07:29:00 【Master. Yi】
Title Description


Topic analysis
Equipped with i i i The number of schemes with odd number of times selected in the row is f i f_i fi, j j j The number of schemes selected for odd number of times is g j g_j gj
A n s = ∑ i m + j n − 2 i j ≤ k f i ∗ g j Ans=\sum_{im+jn-2ij\le k} f_i*g_j Ans=∑im+jn−2ij≤kfi∗gj
f i = q ! [ x q ] ( e x − e − x 2 ) i ( e x + e − x 2 ) n − i ( n i ) f_i=q^i(\frac {e^x+e^{-x}}2)^{n-i}\binom ni fi=qi(2ex+e−x)n−i(in)
It's not easy to push directly ( But it is feasible , There's a little trick , I'll talk about it later )
It would be more comfortable if there was only one power . Consider binomial inversion , h i h_i hi To force there to be i i i Row odd , Any other scheme .
h i = q ! [ x q ] ( e x − e − x 2 ) i e ( n − i ) x ( n i ) = ( 1 2 ) i ( n i ) q ! [ x q ] ∑ j = 0 i ( i j ) ( − 1 ) i − j e x ( n − 2 i + 2 j ) h_i=q^ie^{(n-i)x}\binom ni\\ =(\frac 12)^i\binom niq![x^q]\sum_{j=0}^i\binom ij(-1)^{i-j}e^{x(n-2i+2j)} hi=qie(n−i)x(in)=(21)i(in)q![xq]j=0∑i(ji)(−1)i−jex(n−2i+2j)
and q ! [ x q ] e x ( n − 2 i + 2 j ) = ( n − 2 i + 2 j ) q q![x^q]e^{x(n-2i+2j)}=(n-2i+2j)^q q![xq]ex(n−2i+2j)=(n−2i+2j)q
Then we can convolute .
Binomial inversion will be rolled up again .
We're done f , g f,g f,g After enumeration i i i, j ( n − 2 i ) ≤ k − i m j(n-2i)\le k-im j(n−2i)≤k−im, according to n − 2 i n-2i n−2i You can find the corresponding prefix sum by the positive and negative of .
Note that rounding under negative division is larger .
Then I will talk about how to directly deduce the formula without binomial inversion .
For those two very similar bases , Express one in the form of another , namely :
q ! [ x q ] ( n i ) ( 1 2 ) n ( e x − e − x ) i ( e x + e − x ) n − i = q ! [ x q ] ( n i ) ( 1 2 ) n ( e x + e − x − 2 e − x ) i ( e x + e − x ) n − i = q ! [ x q ] ( n i ) ( 1 2 ) n ∑ j = 0 i ( − 2 ) i − j ( e x + e − x ) n − i + j e − x ( i − j ) = q ! [ x q ] ( n i ) ( 1 2 ) n ∑ j = 0 i ( − 2 ) i − j ∑ k = 0 n − i + j ( n − i + j k ) e ( 2 k − n ) x = ( n i ) ( 1 2 ) n ∑ j = 0 i ( − 2 ) i − j ∑ k = 0 n − i + j ( n − i + j k ) ( 2 k − n ) q q![x^q]\binom ni(\frac 12)^n(e^x-e^{-x})^i(e^x+e^{-x})^{n-i}\\ =q![x^q]\binom ni(\frac 12)^n(e^x+e^{-x}-2e^{-x})^i(e^x+e^{-x})^{n-i}\\ =q![x^q]\binom ni(\frac 12)^n\sum_{j=0}^i(-2)^{i-j}(e^x+e^{-x})^{n-i+j}e^{-x(i-j)}\\ =q![x^q]\binom ni(\frac 12)^n\sum_{j=0}^i(-2)^{i-j}\sum_{k=0}^{n-i+j}\binom {n-i+j}ke^{(2k-n)x}\\ =\binom ni(\frac 12)^n\sum_{j=0}^i(-2)^{i-j}\sum_{k=0}^{n-i+j}\binom {n-i+j}k(2k-n)^q q(21)n(ex−e−x)i(ex+e−x)n−i=q(21)n(ex+e−x−2e−x)i(ex+e−x)n−i=q(21)nj=0∑i(−2)i−j(ex+e−x)n−i+je−x(i−j)=q(21)nj=0∑i(−2)i−jk=0∑n−i+j(kn−i+j)e(2k−n)x=(in)(21)nj=0∑i(−2)i−jk=0∑n−i+j(kn−i+j)(2k−n)q
the second ∑ \sum ∑ Can be seen as G ( i − j ) G(i-j) G(i−j), One convolution can find G G G, Then we can roll it again and find out f f f 了 .
Code( Binomial inversion ):
#include<bits/stdc++.h>
#define maxn 550005
using namespace std;
const int mod = 998244353, inv2 = (mod+1)/2;
int w[maxn],r[maxn],WL,fac[maxn],inv[maxn];
int Pow(int a,int b){
int s=1;for(;b;b>>=1,a=1ll*a*a%mod) b&1&&(s=1ll*s*a%mod);return s;}
int C(int n,int m){
return 1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;}
void init(int n){
w[0]=WL=1; while(WL<=n) WL<<=1; w[1]=Pow(3,(mod-1)/WL);
for(int i=2;i<=WL;i++) w[i]=1ll*w[i-1]*w[1]%mod;
fac[0]=fac[1]=inv[0]=inv[1]=1;
for(int i=2;i<=n;i++) fac[i]=1ll*fac[i-1]*i%mod,inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
for(int i=2;i<=n;i++) inv[i]=1ll*inv[i-1]*inv[i]%mod;
}
int upd(int x){
return x+(x>>31&mod);}
void NTT(int *a,int len,int flg){
for(int i=0;i<len;i++) if(i<(r[i]=r[i>>1]>>1|(i&1?len>>1:0))) swap(a[i],a[r[i]]);
for(int i=2,l=1,v;i<=len;l=i,i<<=1)
for(int j=0,t=WL/i;j<len;j+=i)
for(int k=j,o=0;k<j+l;k++,o+=t)
a[k+l]=upd(a[k]-(v=1ll*w[flg^1?WL-o:o]*a[k+l]%mod)),a[k]=upd(a[k]+v-mod);
if(flg^1) for(int i=0,Inv=mod-(mod-1)/len;i<len;i++) a[i]=1ll*a[i]*Inv%mod;
}
int n,m,qq,A[maxn],B[maxn],f[maxn],g[maxn],h[maxn];
long long q,k,lim;
void calc(int n,int *f){
init(2*n);
memset(A,0,sizeof A),memset(B,0,sizeof B);
for(int i=0;i<=n;i++) A[i]=inv[i],B[i]=1ll*(i&1?mod-1:1)*inv[i]%mod*Pow(upd(n-2*i),qq)%mod;
NTT(A,WL,1),NTT(B,WL,1);
for(int i=0;i<WL;i++) A[i]=1ll*A[i]*B[i]%mod;
NTT(A,WL,-1); memset(h,0,sizeof h);
for(int i=0,pw=1;i<=n;i++,pw=1ll*pw*inv[2]%mod) h[i]=1ll*A[i]*fac[n]%mod*inv[n-i]%mod*pw%mod;
memset(A,0,sizeof A),memset(B,0,sizeof B);
for(int i=0;i<=n;i++) A[i]=1ll*h[i]*fac[i]%mod,B[i]=1ll*inv[n-i]*(n-i&1?mod-1:1)%mod;
NTT(A,WL,1),NTT(B,WL,1);
for(int i=0;i<WL;i++) A[i]=1ll*A[i]*B[i]%mod;
NTT(A,WL,-1);
for(int i=0;i<=n;i++) f[i]=1ll*A[n+i]*inv[i]%mod;
}
int main()
{
freopen("b.in","r",stdin);
freopen("b.out","w",stdout);
scanf("%d%d%lld%lld",&n,&m,&q,&k),qq=q%(mod-1);
if(q==0) return puts("1"),0;
calc(n,f),calc(m,g);
for(int i=1;i<=m;i++) g[i]=(g[i]+g[i-1])%mod;
int ans=0;
for(int i=0;i<=n;i++)
if(n>2*i){
if(k>=1ll*i*m) ans=(ans+1ll*f[i]*g[min((k-1ll*i*m)/(n-2*i),1ll*m)])%mod;
}
else if(n<2*i){
if((lim=(1ll*i*m-k+2*i-n-1)/(2*i-n))<=m) ans=(ans+1ll*f[i]*(g[m]-(lim>0?g[lim-1]:0)))%mod;
}
else if(k-1ll*i*m>=0) ans=(ans+1ll*f[i]*g[m])%mod;
printf("%d\n",(ans+mod)%mod);
}
边栏推荐
- 【LeetCode】-- 17. Letter combination of telephone number
- CMAP of Matplotlib
- 資深OpenStacker - 彭博、Vexxhost昇級為OpenInfra基金會黃金成員
- Atomicinteger atomic operation class
- Sdl-4 PCM playback
- JVM tuning
- [Oracle database] mammy tutorial day04 Sorting Query
- [Oracle database] mammy tutorial day03 Sorting Query
- [STL source code analysis] summary notes (7): ingenious deque
- No response from win10 explorer when dragging files
猜你喜欢

10 advanced concepts that must be understood in learning SQL

Gobang interface of mobile console (C language)

2022 low voltage electrician operation certificate test question simulation test platform operation

big. Js-- use / instance

一、SQLServer2008安装(带密码)、创建数据库、C#窗体项目测试

JVM Learning record (7) - - class Loading Process and parent delegation Model
![[STL source code analysis] summary notes (7): ingenious deque](/img/da/8ec42bfdbbf1b5bd1c2e396c2213e2.jpg)
[STL source code analysis] summary notes (7): ingenious deque

CMAP of Matplotlib

Several transaction modes of Seata

Building a full-featured NAS server with raspberry pie (06): built-in file synchronization tool for penetration
随机推荐
一、SQLServer2008安裝(帶密碼)、創建數據庫、C#窗體項目測試
MS office level II wrong question record [4]
Tetris preliminary
Use definite integral to calculate triangle area
Mistakes in Niuke JS exercise
pycharm出现error.DeprecatedEnv: Env FrozenLake-v0 not found (valid versions include [‘FrozenLake-v1‘])
软件测试周刊(第75期):唯有平视,才能看见真实的自己。
Server parameter adjustment record
Several transaction modes of Seata
【AtCoder2000】Leftmost Ball (DP+组合数)
Summary of classic interview questions
[STL source code analysis] summary note (2): overview of containers
Notes on learning Es5 and ES6
【AtCoder2376】Black and White Tree(博弈)
【CF】 A. New Year Candles
1、 Sqlserver2008 installation (with password), database creation, C form project test
R language Parallel Computing practice tutorial
Regular Expression Matching
Senior openstacker - Bloomberg, vexxhost upgraded to gold member of openinfra Foundation
【Oracle 数据库】奶妈式教程day04 排序查询