条件:

1:每个红色节点的儿子都是黑色节点

2.每个叶子到根路径上的黑点数相等,等于某个常数,称作树的black height

求给定black height和节点数的符合条件的方案数

$black_{h} = x (black_{h-1} + red_{h-1})^2$

$red_{h} = x black_{h}^2$

任意模数的fft

#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, k) for (int i = int(j); i <= int(k); ++ i)
#define dwn(i, j, k) for (int i = int(j); i >= int(k); -- i)
typedef long long LL;
const int MOD = ;
const int N = << ;
const long double PI = acos(-.);
LL red[][N], black[][N], M = ;
struct Complex {
long double r, i;
Complex(long double _r = , long double _i = ) {
r = _r; i = _i;
}
Complex operator + (const Complex &rhs) const {
return Complex(r + rhs.r, i + rhs.i);
}
Complex operator - (const Complex &rhs) const {
return Complex(r - rhs.r, i - rhs.i);
}
Complex operator * (const Complex &rhs) const {
return Complex(r * rhs.r - i * rhs.i, r * rhs.i + i * rhs.r);
}
Complex operator / (long double b) const {
return Complex(r / b, i / b);
}
};
int a[N], b[N], c[N];
Complex conj(Complex &a) {
return Complex(a.r, -a.i);
}
void fft(Complex *a, int n, int t) {
int k = ;
while (( << k) < n) k ++;
rep(i, , n - ) {
int t = ;
rep(j, , k - ) if ((i >> j) & ) t |= ( << (k - - j));
if (i < t) swap(a[i], a[t]);
} for (int l = ; l <= n; l <<= ) {
int m = l >> ;
long double o = * PI / l * t; Complex _w(cos(o), sin(o));
for (int i = ; i < n; i += l) {
Complex w(, );
rep(j, , m - ) {
Complex x = w * a[i + j + m];
a[i + j + m] = a[i + j] - x;
a[i + j] = a[i + j] + x;
w = w * _w;
}
}
}
if (t == -) rep(i, , n - ) a[i] = a[i] / n;
}
void Mul(int *A, int *B, int *C, int len, LL P) {
for(int i = ;i < len; ++i) (A[i] += P) %= P, (B[i] += P) %= P;
static Complex a[N], b[N], Da[N], Db[N], Dc[N], Dd[N];
for(int i = ;i < len; ++i) a[i] = Complex(A[i] & M, A[i] >> );
for(int i = ;i < len; ++i) b[i] = Complex(B[i] & M, B[i] >> );
fft(a, len, ); fft(b, len, );
for(int i = ;i < len; ++i) {
int j = (len - i) & (len - ); static Complex da, db, dc, dd;
da = (a[i] + conj(a[j])) * Complex(0.5, );
db = (a[i] - conj(a[j])) * Complex(, -0.5);
dc = (b[i] + conj(b[j])) * Complex(0.5, );
dd = (b[i] - conj(b[j])) * Complex(, -0.5);
Da[j] = da * dc; Db[j] = da * dd; Dc[j] = db * dc; Dd[j] = db * dd; //顺便区间反转,方便等会直接用DFT代替IDFT
}
for(int i = ;i < len; ++i) a[i] = Da[i] + Db[i] * Complex(, );
for(int i = ;i < len; ++i) b[i] = Dc[i] + Dd[i] * Complex(, );
fft(a, len, ); fft(b, len, );
for(int i = ;i < len; ++i) {
int da = (LL) (a[i].r / len + 0.5) % P; //直接取实部和虚部
int db = (LL) (a[i].i / len + 0.5) % P;
int dc = (LL) (b[i].r / len + 0.5) % P;
int dd = (LL) (b[i].i / len + 0.5) % P;
C[i] = (da + ((LL)(db + dc) << ) + ((LL)dd << )) % P;
}
} int main() {
red[][] = ; red[][] = ;
int len1 = << , len2 = << ; rep(h, , ) {
rep(i, , len1 - ) a[i] = (black[h - ][i] + red[h - ][i]) % MOD, b[i] = a[i];
rep(i, len1, len2 - ) a[i] = b[i] = ;
Mul(a, b, c, len2, MOD);
rep(i, , len1) black[h][i] = c[i - ];
rep(i, , len1 - ) a[i] = black[h][i], b[i] = a[i];
rep(i, len1, len2 - ) a[i] = b[i] = ;
Mul(a, b, c, len2, MOD);
rep(i, , len1) red[h][i] = c[i - ];
} rep(i, , len1) rep(j, , ) {
(red[j][i] += red[j - ][i]) %= MOD;
(black[j][i] += black[j - ][i]) %= MOD;
}
// rep(i, 0, 10) cout << black[1][i] << ' '; cout << '\n';
int k, H, n;
scanf("%d%d", &k, &H);
rep(i, , k) {
scanf("%d", &n);
cout << (red[H][n] + black[H][n]) % MOD << '\n';
}
}

Petrozavodsk Winter Camp, Andrew, 2014, Dichromatic Trees的更多相关文章

  1. Petrozavodsk Winter Camp, Andrew, 2014, Bipartite Bicolored Graphs

    由i个点和j个点组成的二分图个数为 $3^{ij}$,减去不联通的部分得到得到由i,j个点组成的联通二分图个数 $g_{i,j} = 3_{ij} - \sum_{k=1}^i \sum_{l=0}^ ...

  2. Petrozavodsk Winter Camp, Warsaw U, 2014, A The Carpet

    一个地图上有若干障碍,问允许出现一个障碍的最大子矩形为多大? 最大子矩形改编 #include<bits/stdc++.h> using namespace std; #define re ...

  3. Petrozavodsk Winter Camp, Day 8, 2014, Ship

    $dp(i,j)$表示i-j这段还没运走时的状态,包括 运输了多少次,还剩多少空间 每次枚举运输左边还是右边转移 #include <bits/stdc++.h> #define rep( ...

  4. Petrozavodsk Winter Camp, Day 8, 2014, Fine Brochures

    1的个数-块的个数+多减的个数+flag 多减的只会在一个循环末尾出现 #include <bits/stdc++.h> using namespace std; #define rep( ...

  5. Petrozavodsk Winter Camp, Day 8, 2014, Second Trip

    给你一棵树,每次询问一个(a,b),问有多少有路径与a-b没有交集 找lca #include <bits/stdc++.h> using namespace std; #define r ...

  6. Petrozavodsk Winter Camp, Day 8, 2014, Mosaic

    给你三个数字a,b,c,让你用1-m的数字凑出来 结论:有2个1和2个2肯定凑不出来,然后就搜索 #include <bits/stdc++.h> using namespace std; ...

  7. Petrozavodsk Winter Camp, Day 8, 2014, Rectangle Count

    给一个n*m的格点图,问其中有多少个矩形? $ \sum_{x=1}^{nm} \sum_{ab=x} [a + b \leq n](n - a - b + 1)\sum_{cd=x} [c + d ...

  8. 2018 Petrozavodsk Winter Camp, Yandex Cup

    A. Ability Draft solved by RDC 60min start, 148 min AC, 1Y 题意:两只 Dota 队伍,每队 \(n\) 个英雄,英雄一开始无技能,他们需要按 ...

  9. 2019 Petrozavodsk Winter Camp, Yandex Cup C. Diverse Singing 上下界网络流

    建图一共建四层 第一层为N个歌手 第二层为{pi,li} 第三层为{si,li} 第四层为M首歌 除了S和第一层与第三层与T之间的边为[1,INF] 其他边均为[0,1] #include<bi ...

随机推荐

  1. ES6 模块

    概述 在 ES6 前, 实现模块化使用的是 RequireJS 或者 seaJS(分别是基于 AMD 规范的模块化库,  和基于 CMD 规范的模块化库). ES6 引入了模块化,其设计思想是在编译时 ...

  2. Intellij IDEA注册激活破解

    1.2017年适用(2016.3.5到2017.2.4版均生效) 安装IntelliJ IDEA 最新版 启动IntelliJ IDEA 输入 license时,选择输入 [License serve ...

  3. Docker入门5------生产力工具docker-compose

    参考: https://www.cnblogs.com/neptunemoon/p/6512121.html 待续 安装参见docker-compose官网: https://github.com/d ...

  4. bugfree3.0.1-邮件配置

    系统内新建BUG或Case,或者BUG状态有修改时,这些操作都可以伴随邮件通知,提醒指派和抄送给对象及时关注. 配置方法 1.进入C:\xampp\htdocs\bugfree\protected\c ...

  5. python框架之Flask(1)-Flask初使用

    Flask是一个基于 Python 开发并且依赖 jinja2 模板和 Werkzeug WSGI 服务的一个微型框架,对于 Werkzeug 本质是 Socket 服务端,其用于接收 http 请求 ...

  6. java8模拟grouby方法

    public class ListUtils{ /** * list 集合分组 * * @param list 待分组集合 * @param groupBy 分组Key算法 * @param < ...

  7. Docker 基础 (二)

    网络管理 容器网络模式 Docker支持5种网络模式 bridge 默认网络,Docker启动后默认创建一个docker0网桥,默认创建的容器也是添加到这个网桥中 host  容器不会获得一个独立的n ...

  8. Java面试题整理---JVM篇

    1.JVM运行时内存区域划分?   2.内存溢出OOM和堆栈溢出SOE的案例.原因.排查及解决?   3.常用的JVM性能监控工具?   4.JVM参数设置?   5.类加载过程?   6.JVM内存 ...

  9. Docker Kubernetes 服务发现原理详解

    Docker Kubernetes  服务发现原理详解 服务发现支持Service环境变量和DNS两种模式: 一.环境变量 (默认) 当一个Pod运行到Node,kubelet会为每个容器添加一组环境 ...

  10. Angular7 表单

    Angular 表单 input.checkbox.radio. select. textarea 实现在线预约功能 html 文件 <h2>人员登记系统</h2> <d ...