当前位置:网站首页>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;
}
边栏推荐
- [leetcode database 1050] actors and directors who have cooperated at least three times (simple question)
- NFT与数字藏品到底有何区别?
- 谷粒学院的全部学习源码
- Center an element horizontally and vertically
- Learning notes of automatic control principle - Performance Analysis of continuous time system
- Study notes of automatic control principle -- correction and synthesis of automatic control system
- Day06 homework - skill question 6
- PHP和MySQL获取week值不一致的处理
- Which of count (*), count (primary key ID), count (field) and count (1) in MySQL is more efficient? "Suggested collection"
- Qtcreator reports an error: you need to set an executable in the custom run configuration
猜你喜欢

Web overview and b/s architecture

Horizontal comparison of the data of the top ten blue chip NFTs in the past half year

Numpy Foundation

Database operation topic 1

Unity topdown character movement control

The essence of attack and defense strategy behind the noun of network security

Study notes of automatic control principle -- correction and synthesis of automatic control system

Day06 homework -- skill question 2

The lessons of 2000. Web3 = the third industrial revolution?

at、crontab
随机推荐
Numpy Foundation
TCP solves the problem of short write
Set of pl/sql -2
The largest number of statistical absolute values --- assembly language
Self review ideas of probability theory
redis原理和使用-基本特性
Day06 operation -- addition, deletion, modification and query
MySQL 强化知识点
Pat grade a a1076 forwards on Weibo
Grain College of all learning source code
(1) CTS tradefed test framework environment construction
Store a group of positive and negative numbers respectively, and count the number of 0 -- assembly language implementation
数据库操作 技能6
tornado之多进程服务
巴比特 | 元宇宙每日必读:元宇宙的未来是属于大型科技公司,还是属于分散的Web3世界?...
NFT与数字藏品到底有何区别?
Form form
idea快捷键 alt实现整列操作
Web overview and b/s architecture
力扣链表题