fft

分治虽然是万能的,但是太慢了

分治是nlog^2n的,太慢了,于是我们用求逆和开根

设f(x)表示答案为x的方案数

c表示物品的生成函数

那么f=f*f*c+1

f*f表示左右儿子的方案数

c表示根的方案数

+1是空树,也就是+上t(x)=1这个生成函数

然后求根公式得出f=2/(1+sqrt(1-4*g))

为什么是+号呢?因为x=1时方案数=1,那么只能是+号

然后就是多项式开根和求逆

具体看picks博客

然后是卡常

所有数组开int

fft蝴蝶操作一定要开int

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int P = ;
ll power(ll x, int t)
{
ll ret = ;
for(; t; t >>= , x = x * x % P) if(t & ) ret = ret * x % P;
return ret;
}
const int N = ( << ) + ;
int n, k, m;
int rev[N];
ll inv2;
void ntt(int *a, int n, int k, int f)
{
for(int i = ; i < n; ++i) if(i < rev[i]) swap(a[i], a[rev[i]]);
for(int l = ; l <= n; l <<= )
{
ll w = power(, f == ? (P - ) / l : P - - (P - ) / l);
int m = l >> ;
for(int i = ; i < n; i += l)
{
ll t = ;
for(int k = ; k < m; ++k, t = t * w % P)
{
int x = a[i + k], y = t * a[i + k + m] % P;
a[i + k] = (x + y) % P;
a[i + m + k] = (x - y + P) % P;
}
}
}
if(f == -)
{
ll inv = power(n, P - );
for(int i = ; i < n; ++i) a[i] = a[i] * inv % P;
}
}
int a[N], b[N], tmp[N], B[N], c[N];
void poly_inverse(int *a, int *b, int l)
{
if(l == )
{
b[] = power(a[], P - );
return;
}
poly_inverse(a, b, l >> );
int n = , k = ;
while(n <= l) n <<= , ++k;
for(int i = ; i < n; ++i) rev[i] = (rev[i >> ] >> ) | ((i & ) << (k - ));
for(int i = ; i < l; ++i) tmp[i] = a[i];
for(int i = l; i < n; ++i) tmp[i] = ;
ntt(tmp, n, k, );
ntt(b, n, k, );
for(int i = ; i < n; ++i) b[i] = (ll)b[i] * ( - (ll)tmp[i] * b[i] % P + P) % P;
ntt(b, n, k, -);
for(int i = l; i < n; ++i) b[i] = ;
}
void poly_sqrt(int *a, int *b, int l)
{
if(l == )
{
b[] = ;
return;
}
int n = , k = ;
while(n <= l) n <<= , ++k;
poly_sqrt(a, b, l >> );
for(int i = ; i < n; ++i) B[i] = ;
poly_inverse(b, B, l);
for(int i = ; i < n; ++i) rev[i] = (rev[i >> ] >> ) | ((i & ) << (k - ));
for(int i = ; i < l; ++i) tmp[i] = a[i];
for(int i = l; i < n; ++i) tmp[i] = , B[i] = ;
ntt(B, n, k, );
ntt(tmp, n, k, );
ntt(b, n, k, );
for(int i = ; i < n; ++i) b[i] = (ll)inv2 * (b[i] + (ll)B[i] * tmp[i] % P) % P;
ntt(b, n, k, -);
for(int i = l; i < n; ++i) b[i] = ;
}
int main()
{
scanf("%d%d", &n, &m);
for(int i = ; i <= n; ++i)
{
int x;
scanf("%d", &x);
c[x] -= ;
}
inv2 = power(, P - );
int len = ;
while(len <= m) len <<= ;
++c[];
for(int i = ; i <= m; ++i) if(c[i] < ) c[i] += P;
poly_sqrt(c, b, len);
++b[];
b[] %= P;
poly_inverse(b, a, len);
for(int i = ; i <= m; ++i) printf("%d\n", a[i] * % P);
return ;
}

bzoj3625的更多相关文章

  1. 【bzoj3625】【xsy1729】小朋友和二叉树

    [bzoj3625]小朋友与二叉树 题意 我们的小朋友很喜欢计算机科学,而且尤其喜欢二叉树. 考虑一个含有n个互异正整数的序列c[1],c[2],...,c[n].如果一棵带点权的有根二叉树满足其所有 ...

  2. 【BZOJ3625】【CF438E】小朋友和二叉树 NTT 生成函数 多项式开根 多项式求逆

    题目大意 考虑一个含有\(n\)个互异正整数的序列\(c_1,c_2,\ldots ,c_n\).如果一棵带点权的有根二叉树满足其所有顶点的权值都在集合\(\{c_1,c_2,\ldots ,c_n\ ...

  3. BZOJ3625 [Codeforces Round #250]小朋友和二叉树(生成函数+多项式开根)

    设f(n)为权值为n的神犇二叉树个数.考虑如何递推求这个东西. 套路地枚举根节点的左右子树.则f(n)=Σf(i)f(n-i-cj),cj即根的权值.卷积的形式,cj也可以通过卷上一个多项式枚举.可以 ...

  4. 【BZOJ3625/CF438E】小朋友和二叉树(多项式求逆,多项式开方)

    [BZOJ3625/CF438E]小朋友和二叉树(多项式求逆,多项式开方) 题面 BZOJ CodeForces 大致题意: 对于每个数出现的次数对应的多项式\(A(x)\) 求\[f(x)=\fra ...

  5. [bzoj3625][Codeforces 250 E]The Child and Binary Tree(生成函数+多项式运算+FFT)

    3625: [Codeforces Round #250]小朋友和二叉树 Time Limit: 40 Sec  Memory Limit: 256 MBSubmit: 650  Solved: 28 ...

  6. BZOJ3625: [Codeforces Round #250]小朋友和二叉树

    Description 我们的小朋友很喜欢计算机科学,而且尤其喜欢二叉树.考虑一个含有n个互异正整数的序列c[1],c[2],...,c[n].如果一棵带点权的有根二叉树满足其所有顶点的权值都在集合{ ...

  7. NTT+多项式求逆+多项式开方(BZOJ3625)

    定义多项式$h(x)$的每一项系数$h_i$,为i在c[1]~c[n]中的出现次数. 定义多项式$f(x)$的每一项系数$f_i$,为权值为i的方案数. 通过简单的分析我们可以发现:$f(x)=\fr ...

  8. 2019.01.01 bzoj3625:小朋友和二叉树(生成函数+多项式求逆+多项式开方)

    传送门 codeforces传送门codeforces传送门codeforces传送门 生成函数好题. 卡场差评至今未过 题意简述:nnn个点的二叉树,每个点的权值KaTeX parse error: ...

  9. 【BZOJ3625】【codeforces438E】小朋友和二叉树 生成函数+多项式求逆+多项式开根

    首先,我们构造一个函数$G(x)$,若存在$k∈C$,则$[x^k]G(x)=1$. 不妨设$F(x)$为最终答案的生成函数,则$[x^n]F(x)$即为权值为$n$的神犇二叉树个数. 不难推导出,$ ...

  10. BZOJ3625: 小朋友和二叉树

    传送门 Sol 设 \(f_x\) 表示权值为 \(x\) 的二叉树的个数 设 \(s_x\) 表示是否有 \(x\) 这种权值可以选择 那么 \[f_n=\sum_{i=0}^{n}\sum_{j= ...

随机推荐

  1. java性能监控工具jcmd-windows

    jcmd Sends diagnostic command requests to a running Java Virtual Machine (JVM). Synopsis jcmd [-l|-h ...

  2. flex 节点删除

    <mx:Script>        <![CDATA[            protected function btn1_clickHandler(evt:MouseEvent ...

  3. win7自带照片查看器

    win10如何找回自带的照片查看器   方法/步骤   1 首先,我们打开一个记事本,可以点击win+r打开运行框,然后在运行框中输入notepad.或者在桌面右键点击里面的新建,然后在新建中找到文本 ...

  4. 实现iOS7上tableView的切割线像iOS6中的效果

    iOS7上tableView的切割线左边短了一点,要实现和iOS6中的效果还是有方法的,UITableView头文件中个属性: @property (nonatomic)         UIEdge ...

  5. Spring Boot 测试时的日志级别

    1.概览 该教程中,我将向你展示:如何在测试时设置spring boot 日志级别.虽然我们可以在测试通过时忽略日志,但是如果需要诊断失败的测试,选择正确的日志级别是非常重要的. 2.日志级别的重要性 ...

  6. 您的安全性偏好设置仅允许安装来自 App Store 和被认可的开发者的应用

    您的安全性偏好设置仅允许安装来自 App Store 和被认可的开发者的应用. 安装macOS Sierra后,会发现系统偏好设置的“安全与隐私”中默认已经去除了允许“任何来源”App的选项,无法运行 ...

  7. C++基本数据类型及类型转换

    http://blog.csdn.net/pipisorry/article/details/25346379 c++基本数据类型 什么样的数据算是byte类型,int类型,float类型,doubl ...

  8. ContentPresenter理解

    这是2年前写了一篇文章 http://www.cnblogs.com/Clingingboy/archive/2008/07/03/wpfcustomcontrolpart-1.html 我们先来看M ...

  9. php 静态成员(static)抽象类(abstract)和接口(interface)

    首先看一下静态成员(static)和普通成员(public; protect; private)的区别: 静态成员是属于类的,普通成员是属于对象的: 例如: <?php header(" ...

  10. Please read "Security" section of the manual to find out how to run mysqld as root!

    [root@test ~]# /usr/local/mysql/bin/mysqld2018-08-05T08:29:05.143142Z 0 [Warning] [MY-011070] [Serve ...