QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 512 MB Total points: 100

#6203. 三色树

Statistics

请你对满足以下要求的 $n$ 个节点的 无标号无根树 计数:

  1. 每个节点是三种颜色之一:红,蓝,黄
  2. 红色节点度数不超过 $4$,蓝色和黄色节点度数均不超过 $3$
  3. 黄色节点不能相邻

注意 无标号无根树 的意义是:如果两颗树可以通过重新编号的方法使得对应点颜色相同,对应连边一致,则认为是同一颗树。

答案对输入的质数 $P$ 取模。

输入格式

两个整数,$n, P$ 意义如题面所示。

输出格式

一个整数,表示方案数对 $P$ 取模的结果。

样例一

input

2 998244353

output

5

样例二

input

3 998244353

output

15

样例三

input

20 998244353

output

578067492

限制与约定

对于 $100\%$ 的数据,保证 $1\le n \le 3000, 9\times 10^8 \le P \le 1.01\times 10^9$

测试点编号$n$ 是偶数,$P = 998244353$$n$ 是奇数,$P = 998244353$$n$ 是偶数$n$ 是奇数
$n\le 7$$1$$2$$3$$4$
$n\le 20$$5$$6$$7$$8$
$n\le 60$$9$$10$$11$$12$
$n\le 300$$13$$14$$15$$16$
$n\le 3000$$17$$18$$19$$20$

Discussions

About Discussions

The discussion section is only for posting: Editorials, 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. Submitting multiple issues may cause your account to be banned.
  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.