QOJ.ac

QOJ

Time Limit: 1.5 s Memory Limit: 1024 MB Total points: 100

#9650. 链覆盖

Statistics

题目背景

你的学弟向你请教这样一道题:

  • 给定一颗 $n$ 个点的有根树,初始所有点均为白色。
  • 你可以执行不超过 $k$ 次操作,每次操作为选定一个点,把它到根简单路径上的所有点涂成黑色。
  • 求你最终最多能涂黑多少点。对 $k = 1 ∼ n$ 分别求解。

这当然不是什么难题,你很快向学弟解释清楚了这应该怎么做,他惊叹于做法的巧妙,然后满意地离开了。

你看着他离去的身影,想起两三年前,你第一次得知这道题怎么做时,也曾为这道题的解法赞叹过。但对于现在的你来说,这也并没有什么神奇之处,只是一个平凡的套路罢了。

但熟知的原题与结论并不一定真的就乏味无趣、无甚可观,这样想着,你记录下了这道题:

题目描述

  • 给定一颗 $n$ 个点的有根树,初始所有点均为白色。
  • 你可以执行不超过 $k$ 次操作,每次操作为选定一个点,把它到根简单路径上的所有点涂成黑色。
  • 求你最终最多能涂黑多少点。对 $k = 1 ∼ n$ 分别求解。

记对于有标号有根树 $T$,上述问题在 $k = i$ 时的答案为 $ans(T, i)$。

给定 $n, \text{mod}$,对所有 $1 ≤ k ≤ n, 1 ≤ m ≤ n$,计算有多少不同的 $n$ 个点以 $1$ 为根的有标号树 $T$ 满足 $ans(T, k) = m$。答案对 $\text{mod}$ 取模。

两颗有标号以 $1$ 为根的树被认为是不同的,当且仅当它们的边集不同。

输入格式

一行两个整数 $n, \text{mod}$。

输出格式

输出 $n$ 行,每行 $n$ 个整数,第 $k$ 行的第 $m$ 个整数表示满足 $ans(T, k) = m$ 的不同的 $n$ 个点以 $1$ 为根的有标号树 $T$ 的数量对 $\text{mod}$ 取模的结果。

样例

样例 #1

样例输入 #1
2 998244353
样例输出 #1
0 1 
0 1

样例 #2

样例输入 #2
3 998244353
样例输出 #2
0 1 2 
0 0 3 
0 0 3

样例 #3

样例输入 #3
4 998244353
样例输出 #3
0 1 9 6 
0 0 1 15 
0 0 0 16 
0 0 0 16

样例 #4

样例输入 #4
5 998244353
样例输出 #4
0 1 40 60 24 
0 0 1 28 96 
0 0 0 1 124 
0 0 0 0 125 
0 0 0 0 125

样例 #5

样例输入 #5
6 998244353
样例输出 #5
0 1 195 560 420 120 
0 0 1 75 500 720 
0 0 0 1 75 1220 
0 0 0 0 1 1295 
0 0 0 0 0 1296 
0 0 0 0 0 1296

数据范围

本题使用捆绑测试,你只有通过一个子任务的所有测试点,才能获得这个子任务的分数。

子任务编号 $n \le$ 分值
$1$ $5$ $1$
$2$ $10$ $9$
$3$ $20$ $10$
$4$ $32$ $15$
$5$ $40$ $5$
$6$ $50$ $15$
$7$ $65$ $5$
$8$ $80$ $5$
$9$ $120$ $15$
$10$ $300$ $20$

对于所有数据:$1 ≤ n ≤ 300$,$10^8 ≤ \text{mod} ≤ 1.05 \times 10^9$,保证 $\text{mod}$ 是质数。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.