QOJ.ac

QOJ

Time Limit: 6 s Memory Limit: 512 MB Total points: 10

#1387. 粉刷栅栏 [B]

Statistics

今年的秋雨彻底毁坏了 Potyczek 先生栅栏上的油漆。必须尽快用特殊的蓝色防腐剂覆盖栅栏,以免即将到来的冬天造成不可逆的损坏。Potyczek 先生请邻居勤劳的儿子 Bajtek 来完成这项工作。今天早上,男孩完成了任务,但他做得相当草率,因为他急着去参加下一轮的算法竞赛。

Potyczek 先生的栅栏由 $n$ 块木板组成,每块木板被分成 $m$ 个等长的段。Bajtek 对每块木板从上到下只刷了一次漆,但这很可能不足以将其完全涂满。尽管如此,在每块木板上,被涂漆的部分是一个连续的段区间,且每一段要么被完全涂漆,要么完全未涂漆。此外,男孩涂漆的栅栏部分是连通的,即对于任意两块相邻的木板,它们上面被涂漆的段区间具有非空的交集。

例如,涂漆后的栅栏可能如下所示:

而以下情况由于三个不同的原因是不可能的: 第 1 块木板完全没有被涂漆。 第 3 块木板上被涂漆的部分不是一个连续的片段。 * 第 5 块和第 6 块木板上被涂漆的段区间是不相交的。

请编写一个程序,计算 Bajtek 按照上述规则涂漆栅栏的不同方式有多少种。如果两种涂漆方式中存在某一块木板的某一段在一种方式中被涂漆而在另一种方式中未被涂漆,则认为这两种方式是不同的。方案数可能非常大,因此只需输出其对质数 $p$ 取模后的结果。

输入格式

输入的第一行也是唯一一行包含三个正整数 $n, m$ 和 $p$ ($1 \le n \cdot m \le 10^7$, $10^8 \le p \le 10^9$, $p \in \mathbb{P}$),分别表示木板的数量、每块木板上的段数以及质数 $p$。

输出格式

输出一行一个整数,表示不同涂漆方式的数量对 $p$ 取模后的结果。

样例

样例输入 1

3 2 100000007

样例输出 1

17

样例输入 2

6 9 813443923

样例输出 2

57

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.