QOJ.ac

QOJ

حد الوقت: 20 s حد الذاكرة: 512 MB مجموع النقاط: 100

#13604. 双色树

الإحصائيات

二色树(Dichromatic trees),目前更常被称为红黑树(red-black trees),是一种用于有序集合的数据结构,最初由 Rudolf Bayer 于 1972 年发明,后来由 Leonidas Guibas 和 Robert Sedgewick 进行了改进。

红黑树是一棵有根二叉树,其中每个顶点都被染成红色或黑色。每个顶点可以有一个左儿子和一个右儿子。满足以下条件:

  • 红色顶点的儿子必须是黑色的。
  • 考虑从根节点到任何缺少子节点的“空位置”的路径。所有这些路径必须包含相同数量的黑色顶点。这个数量被称为树的黑高度(black height)。

给定 $n$ 和 $h$,求有多少种包含 $n$ 个顶点且黑高度至多为 $h$ 的红黑树。注意,结构相同但顶点颜色不同的树被视为不同的树。输出答案对 $258\,280\,327$ 取模的结果。

输入格式

输入文件包含 $k$ 组测试数据。一个输入文件中的所有测试数据共享相同的 $h$。

第一行包含两个整数:$k$ 和 $h$($1 \le k \le 131\,072$,$0 \le h \le 16$)。

第二行包含 $k$ 个整数:$n_1, n_2, \dots, n_k$($1 \le n_i \le 131\,072$)。

输出格式

输出 $k$ 个数,对于每个 $i$($1$ 到 $k$),输出包含 $n_i$ 个顶点且黑高度至多为 $h$ 的红黑树数量。

样例

输入样例 1

10 2
1 2 3 4 5 6 7 8 9 10

输出样例 1

2 2 3 8 14 20 34 56 90 164

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.