当前位置:网站首页>The child and binary tree- open root inversion of polynomials
The child and binary tree- open root inversion of polynomials
2022-07-26 09:05:00 【Qin xiaobaa】
We set up F(x) The total weight is x Number of tree existence schemes
Then we enumerate the root nodes of the tree , The size of the left and right subtrees , You can get F(x)
Into a formula
namely F(x)=G(x) F(x)^2
However, it should be noted that ,x=0, Constant term of time 1
F(x)= G(x)F(x)^2+1
G(x)F(x)^2-F(x)+1=0
/ 2G(x)
If we recursively find G(x) Inverse element , We will find that when we recurse to g(0) When ,g(0)=0, Therefore, mathematical transformation is needed
g(x) It can be preprocessed , Then find out 1-4G(x), Re root , Then find the inverse element , Double it again , Lots of details , Code length
# include<iostream>
# define GG 3
# define MAXN 262145
# define mod 998244353
# define inv 499122177
using namespace std;
typedef long long int ll;
ll temp[MAXN],B[MAXN],rev[MAXN],tp[MAXN],tq[MAXN],ta[MAXN],tb[MAXN];
ll A[MAXN];
ll G[MAXN];
void init(int k)
{
int len=(1<<k);
for(int i=0;i<len;i++)
{
rev[i]=0;
}
for(int i=0;i<len;i++)
{
rev[i]=(rev[i>>1]>>1)|((i&1)<<(k-1));
}
return ;
}
ll qp(ll base, ll pow)
{
ll ans=1;
while(pow)
{
if(pow&1)
{
ans=ans*base%mod;
}
pow>>=1;
base=base*base%mod;
}
return ans;
}
void NTT(ll *a,int n,int flag)
{
for(int i=0;i<n;i++)
{
if(i<rev[i])
{
swap(a[i],a[rev[i]]);
}
}
for(int h=1;h<n;h<<=1)
{
ll gn=qp(GG,(mod-1)/(h<<1));
if(flag==-1)
{
gn=qp(gn,mod-2);
}
for(int j=0;j<n;j+=2*h)
{
ll g=1;
for(int k=j;k<j+h;k++)
{
ll x=a[k];
ll y=a[k+h]*g%mod;
a[k]=(x+y)%mod;
a[k+h]=((x-y)%mod+mod)%mod;
g=g*gn%mod;
}
}
}
if(flag==-1)
{
ll invn=qp(n,mod-2);
for(int i=0;i<n;i++)
{
a[i]=a[i]*invn%mod;
}
}
return ;
}
void mul(ll *a,ll*b,ll*c,int n,int m)
{
int k=1,s=2;
while((1<<k)<n+m-1)
{
k++;
s<<=1;
}
init(k);
for(int i=0;i<n;i++)
{
tp[i]=a[i];
}
for(int i=n;i<s;i++)
{
tp[i]=0;
}
for(int i=0;i<n;i++)
{
tq[i]=b[i];
}
for(int i=n;i<s;i++)
{
tq[i]=0;
}
NTT(tp,s,1);
NTT(tq,s,1);
for(int i=0;i<s;i++)
{
c[i]=tp[i]*tq[i]%mod;
}
NTT(c,s,-1);
}
void getinv(ll *a,ll*b,int n)
{
if(n==1)
{
b[0]=qp(a[0],mod-2);
return ;
}
getinv(a,b,(n+1)>>1);
int k=1,s=2;
while((1<<k)<n+n-1)
{
k++;
s<<=1;
}
init(k);
for(int i=0;i<n;i++)
{
ta[i]=a[i];
}
for(int i=n;i<s;i++)
{
ta[i]=0;
}
NTT(ta,s,1);
NTT(b,s,1);
for(int i=0;i<s;i++)
{
b[i]=((2ll-ta[i]*b[i])%mod+mod)%mod*b[i]%mod;
}
NTT(b,s,-1);
for(int i=n;i<s;i++)
{
b[i]=0;
}
return ;
}
void sqrt(ll *a,ll*b,int n)
{
if(n==1)
{
b[0]=1;
return ;
}
sqrt(a,b,(n+1)>>1);
int k=1,s=2;
while((1<<k)<n+n-1)
{
k++;
s<<=1;
}
init(k);
for(int i=0;i<s;i++)
{
tb[i]=0;
}
getinv(b,tb,n);
mul(a,tb,tb,n,n);
for(int i=0;i<s;i++)
{
b[i]=(b[i]+tb[i])*inv%mod;
}
}
int main ()
{
int n,m;
cin>>n>>m;
for(int i=0;i<n;i++)
{
int x;
cin>>x;
G[x]=1;
}
temp[0]=1;
for(int i=1;i<=m;i++)
{
temp[i]=mod-4*G[i]%mod;
}
sqrt(temp,B,m+1);
B[0]++;
getinv(B,A,m+1);
for(int i=1;i<=m;i++)
{
A[i]=A[i]*2%mod;
cout<< A[i]<<'\n';
}
return 0;
}
边栏推荐
- js闭包:函数和其词法环境的绑定
- Kotlin properties and fields
- 03 exception handling, state keeping, request hook -- 04 large project structure and blueprint
- 209. Subarray with the smallest length
- day06 作业---技能题7
- CSDN TOP1“一个处女座的程序猿“如何通过写作成为百万粉丝博主?
- 220. Presence of repeating element III
- Advanced mathematics | Takeshi's "classic series" daily question train of thought and summary of error prone points
- The lessons of 2000. Web3 = the third industrial revolution?
- 堆外内存的使用
猜你喜欢
论文笔记: 知识图谱 KGAT (未完暂存)
Probability model in machine learning
Babbitt | metauniverse daily must read: does the future of metauniverse belong to large technology companies or to the decentralized Web3 world
Study notes of automatic control principle --- stability analysis of control system
Zipkin安装和使用
Day06 homework -- skill question 1
Study notes of automatic control principle -- correction and synthesis of automatic control system
数据库操作技能7
220. Presence of repeating element III
Sklearn machine learning foundation (linear regression, under fitting, over fitting, ridge regression, model loading and saving)
随机推荐
Set of pl/sql -2
【final关键字的使用】
Day06 operation -- addition, deletion, modification and query
力扣——二叉树剪枝
CF1481C Fence Painting
Node-v download and application, ES6 module import and export
网络安全漫山遍野的高大上名词之后的攻防策略本质
Summary of common activation functions for deep learning
mysql函数
Database operation skills 6
Datax的学习笔记
NPM add source and switch source
多项式开根
Announcement | FISCO bcos v3.0-rc4 is released, and the new Max version can support massive transactions on the chain
Vision Group Training Day5 - machine learning, image recognition project
Pat grade a a1013 battle over cities
Uni app simple mall production
机器学习中的概率模型
(2006,Mysql Server has gone away)问题处理
How to quickly learn a programming language