http://codeforces.com/contest/438/problem/E

题意:询问每个点权值在 $c_1, c_2, ..., c_m$ 中,总权值和为 $s$ 的二叉树个数。请给出每个$s \in [1,S]$ 对应的答案。($S,m < 10^5$)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=(1e5+10)*4, mo=998244353;
int two, G[30], nG[30], rev[N];
int ipow(int a, int b) { int x=1; for(; b; b>>=1, a=(ll)a*a%mo) if(b&1) x=(ll)x*a%mo; return x; }
void fft_init() {
two=ipow(2, mo-2); G[23]=ipow(3, (mo-1)/(1<<23)); nG[23]=ipow(G[23], mo-2);
for(int i=22; i; --i) G[i]=(ll)G[i+1]*G[i+1]%mo, nG[i]=(ll)nG[i+1]*nG[i+1]%mo;
}
int getlen(int n) {
int len=1, bl=-1;
for(; len<n; len<<=1, ++bl);
for(int i=1; i<len; ++i) rev[i]=(rev[i>>1]>>1)|((i&1)<<bl);
return len;
}
void fft(int *a, int n, int f) {
for(int i=0; i<n; ++i) if(i<rev[i]) swap(a[i], a[rev[i]]);
for(int m=2, now=1; m<=n; m<<=1, ++now) {
int mid=m>>1, w=1, wn=G[now], u, v; if(f) wn=nG[now];
for(int i=0; i<n; i+=m, w=1)
for(int j=0; j<mid; ++j) {
u=a[i+j], v=(ll)a[i+j+mid]*w%mo;
a[i+j]=(u+v)%mo; a[i+j+mid]=(u-v+mo)%mo; w=(ll)w*wn%mo;
}
}
}
void getinv(int *a, int *b, int n) {
if(n==1) { b[0]=ipow(a[0], mo-2); return; }
getinv(a, b, (n+1)>>1);
static int c[N], d[N];
memcpy(c, a, sizeof(int)*(n)); memcpy(d, b, sizeof(int)*((n+1)>>1));
int len=getlen(n+n-1), nlen=ipow(len, mo-2);
fft(c, len, 0); fft(d, len, 0);
for(int i=0; i<len; ++i) d[i]=(ll)d[i]*(2-(ll)d[i]*c[i]%mo+mo)%mo;
fft(d, len, 1);
for(int i=0; i<n; ++i) b[i]=(ll)d[i]*nlen%mo;
memset(c, 0, sizeof(int)*(len)); memset(d, 0, sizeof(int)*(len));
}
void getroot(int *a, int *b, int n) {
if(n==1) { b[0]=sqrt(a[0]); return; }
getroot(a, b, (n+1)>>1);
static int c[N], d[N];
memcpy(c, a, sizeof(int)*(n));
getinv(b, d, n);
int len=getlen(n+n-1), nlen=ipow(len, mo-2);
fft(c, len, 0); fft(d, len, 0);
for(int i=0; i<len; ++i) d[i]=(ll)c[i]*d[i]%mo;
fft(d, len, 1);
for(int i=0; i<n; ++i) b[i]=(ll)two*((b[i]+(ll)d[i]*nlen%mo)%mo)%mo;
memset(d, 0, sizeof(int)*(len)); memset(c, 0, sizeof(int)*(len));
}
int a[N], b[N];
int main() {
fft_init();
int m, n; scanf("%d%d", &n, &m);
for(int i=0; i<n; ++i) { int x; scanf("%d", &x); if(x<=m) a[x]=mo-4; }
a[0]=1;
getroot(a, b, m+1);
b[0]=(b[0]+1)%mo;
getinv(b, a, m+1);
for(int i=1; i<=m; ++i) printf("%d\n", (a[i]<<1)%mo);
return 0;
}

  

多项式求根= =具体看picks博客..http://picks.logdown.com/posts/202388-square-root-of-polynomial

其实想到了母函数然后知道用倍增来求根本题就解决了= =...跪跪跪orz

一定要注意那些多项式的次数啊!!!一定要想明白啊!!!

【CF】438E. The Child and Binary Tree的更多相关文章

  1. 【LeetCode】297. Serialize and Deserialize Binary Tree 解题报告(Python)

    [LeetCode]297. Serialize and Deserialize Binary Tree 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode ...

  2. 【LeetCode】662. Maximum Width of Binary Tree 解题报告(Python)

    [LeetCode]662. Maximum Width of Binary Tree 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.co ...

  3. 【leetcode】979. Distribute Coins in Binary Tree

    题目如下: Given the root of a binary tree with N nodes, each node in the tree has node.val coins, and th ...

  4. 【LeetCode】979. Distribute Coins in Binary Tree 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 日期 题目地址:https://leetcod ...

  5. 【LeetCode】104 - Maximum Depth of Binary Tree

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  6. 【LeetCode】111 - Minimum Depth of Binary Tree

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...

  7. 【easy】111. Minimum Depth of Binary Tree求二叉树的最小深度

    求二叉树的最小深度: /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; ...

  8. 【easy】104. Maximum Depth of Binary Tree 求二叉树的最大深度

    求二叉树的最大深度 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; ...

  9. 【LeetCode】104. Maximum Depth of Binary Tree (2 solutions)

    Maximum Depth of Binary Tree  Given a binary tree, find its maximum depth. The maximum depth is the ...

随机推荐

  1. eclipse中的任务标记(TODO、FIXME、XXX)

    eclipse Task Tags: TODO -用来提醒该标识处的代码有待返回继续编写.更新或者添加.该标签通常在注释块的源文件顶部. FIXME -该标签用来提醒你代码中存在稍后某个时间需要修改的 ...

  2. 网站性能测试工具--MS Web Application Stress Tool

    MS Web Applicaion Stress Tool 是一款网页测试的性能工具,具体的使用可以参考下面这篇博客文章 http://cuisuqiang.iteye.com/blog/193640 ...

  3. 記錄一次CRS-0184: Cannot communicate with the CRS daemon的解決

    1. 描述: 使用crs_stat –t 命令查看rac服務,直接報CRS-0184: Cannot communicate with the CRS daemon.錯誤 但是奇怪的是我們的DB是沒有 ...

  4. 吐个槽,对VB6.0 还有VBS 说ByeBye

    往事不堪回首,折腾了个把月的老系统,心中郁结,不吐不快.系统架构是ASP +VBS +VB6.0 + SQL Server2000, 第一个版本开发完成大概是在2000年.基本是处于交接无力,看代码就 ...

  5. jQuery实现无限加载瀑布流特效

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. Parallel.js初探续集

    @author mrbean 例子均来源于github parallel.js 昨天写的第一篇今天一看居然有50+的阅读量了,感觉很激动啊,但是也有点害怕毕竟这只是自己笔记性质的一点东西,所以赶紧拿起 ...

  7. 10g ASM下修改control file的位置

    1.查看位置以及name是否正确 SQL> sho parameter name NAME TYPE VALUE ------------------------------------ --- ...

  8. Cygwin的安装与配置

    去cygwin的官网去下载: 安装: 初次安装 卸载 使用过程中安装新的工具包 参考http://blog.csdn.net/superbinbin1/article/details/10147421 ...

  9. HDU 2243 考研路茫茫——单词情结(AC自动机+矩阵)

    考研路茫茫——单词情结 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  10. 关于移动端1px边框问题

    <div class="z_nei_list"> <div class="z_name_left font-size3">身份证号:&l ...