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. .netWeb方向:语言+技术

    常用语言+技术 C# T-Sql ADO.NEt JavaScript Asp.Net MVC HTML CSS DOM AJAX Entity Framework Regular expressio ...

  2. ASP.NET MVCでResponse Headerのサーバーバージョンをどうやって隠しますか?

    本来是发布在客户的Wiki上的,所以用日语写. ---------------------------------------------------------------------------- ...

  3. Yii 同域名的单点登录 SSO实现

    SSO (Single Sign-on) 顾名思义就是几个子项目共用一个登录点. 原理简单来说就是服务端session 共享, 客户端跨域cookies. 实现非常简单,protected/confi ...

  4. 蛋疼的Fedora17

    在公司给同事要安装ASM oracle 11g,说要在forder17上安装,于是乎我先在自己的虚拟机上安装了一个forder17,遇到了几个很蛋疼的问题:      1. 安装的时候没有创建普通用户 ...

  5. HDU4495 Rectangle

    求组成的等腰三角形面积最大值. 对此题的总结:暴力出奇迹 组成的三角形放置方式一共只有4种,用ans表示目前已知的最长三角形的边长,从上到下,从左到右枚举顶点,再枚举边长,一个重要剪枝是枚举边长l时先 ...

  6. 在Virtulbox上装Ubuntu

    做个程序员,会用Linux,这应该是最基本的要求吧.可惜本人经常用Windows,只是偶尔去服务器上做些操作的时候才接触到linux.so,我要学Linux.刚学所以还是先装个虚拟机吧,等在虚拟机上用 ...

  7. memset中的sizeof

    记录memset中的sizeof的用法, unsigned char *buff = (unsigned char*) malloc(128 * sizeof(char)); //错误的:memset ...

  8. loj 1412(树上最长直径的应用)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1412 思路:好久没写题解了,有点手生,这题从昨天晚上wa到现在终于是过了...思想其实 ...

  9. 【maven 报错】maven项目执行maven install时报错Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)

    在使用maven新建的web项目中,执行 执行如上的这两个操作,报错: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-co ...

  10. BurpSuite拦截HTTPS请求

    1.设置好浏览器代理 2. 3.请求https站点(比如https://www.baidu.com),以火狐浏览器例子: 4. 这一步主要是为了显示[我已充分了解可能的风险],如果有,就不用做以上步骤 ...