Petrozavodsk Winter Camp, Andrew, 2014, Dichromatic Trees
条件:
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的更多相关文章
- 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}^ ...
- Petrozavodsk Winter Camp, Warsaw U, 2014, A The Carpet
一个地图上有若干障碍,问允许出现一个障碍的最大子矩形为多大? 最大子矩形改编 #include<bits/stdc++.h> using namespace std; #define re ...
- Petrozavodsk Winter Camp, Day 8, 2014, Ship
$dp(i,j)$表示i-j这段还没运走时的状态,包括 运输了多少次,还剩多少空间 每次枚举运输左边还是右边转移 #include <bits/stdc++.h> #define rep( ...
- Petrozavodsk Winter Camp, Day 8, 2014, Fine Brochures
1的个数-块的个数+多减的个数+flag 多减的只会在一个循环末尾出现 #include <bits/stdc++.h> using namespace std; #define rep( ...
- Petrozavodsk Winter Camp, Day 8, 2014, Second Trip
给你一棵树,每次询问一个(a,b),问有多少有路径与a-b没有交集 找lca #include <bits/stdc++.h> using namespace std; #define r ...
- Petrozavodsk Winter Camp, Day 8, 2014, Mosaic
给你三个数字a,b,c,让你用1-m的数字凑出来 结论:有2个1和2个2肯定凑不出来,然后就搜索 #include <bits/stdc++.h> using namespace std; ...
- 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 ...
- 2018 Petrozavodsk Winter Camp, Yandex Cup
A. Ability Draft solved by RDC 60min start, 148 min AC, 1Y 题意:两只 Dota 队伍,每队 \(n\) 个英雄,英雄一开始无技能,他们需要按 ...
- 2019 Petrozavodsk Winter Camp, Yandex Cup C. Diverse Singing 上下界网络流
建图一共建四层 第一层为N个歌手 第二层为{pi,li} 第三层为{si,li} 第四层为M首歌 除了S和第一层与第三层与T之间的边为[1,INF] 其他边均为[0,1] #include<bi ...
随机推荐
- Intellij IDEA注册激活破解
1.2017年适用(2016.3.5到2017.2.4版均生效) 安装IntelliJ IDEA 最新版 启动IntelliJ IDEA 输入 license时,选择输入 [License serve ...
- zabbix结合grafana打造炫酷监控界面
一.grafana介绍 grafana是一个开源的数据展示工具, 是一个开箱即用的可视化工具,具有功能齐全的度量仪表盘和图形编辑器,有灵活丰富的图形化选项,可以混合多种风格,支持多个数据源特点. za ...
- LwIP协议栈规范翻译——摘要目录
摘要 LwIP是一种TCP/IP协议栈的实现.LwIP协议栈专注于减少内存的使用和代码的大小,使LwIP适用于嵌入式系统中在有限的资源下能够使用小型的客户机.为了减少处理和内存的需求,LwIP使用裁剪 ...
- Python Async/Await入门指南
转自:https://zhuanlan.zhihu.com/p/27258289 本文将会讲述Python 3.5之后出现的async/await的使用方法,以及它们的一些使用目的,如果错误,欢迎指正 ...
- 字典排序 sorted
a = {6:2,8:0,1:4,-5:6,99:11,4:22} print( sorted(a.items()) ) #默认安照key排序的print( sorted(a.items(),key= ...
- spring internalTransactionAdvisor 事务 advisor 初始化过程
spring internalTransactionAdvisor 事务 advisor 初始化过程:
- Grunt: 拼接代码,js丑化(压缩),css压缩,html压缩,观察文件,拷贝文件,删除文件,压缩文件
准备工作 grunt 基于nodeJs所以 nodeJs需要的基础配置都需要安装 1.Grunt 安装 npm install -g grunt-cli 这是全局安装 2.在当前文件下npm init ...
- Docker 部署 portainer
Docker 部署 portainer 环境: docker 版本 :18.09.1 主机地址:192.168.1.81 一.部署 porttainer 1.修改docker配置文件,开放端口. vi ...
- markdown的css样式(自己写的)
markdown的css样式,这些是我自己配置的,感觉可以的话你可以添加下,不适合自己的话可以仿照第二种自己写个比较好的css样式. 第一种 /* RESET ==================== ...
- Java基础学习-注释的概述和分类
/* 注释:用于解释说明程序的文字 分类: 单行:// 多行:/**/ 作用:解释说明程序,提高程序的阅读性 */ ...