QOJ.ac

QOJ

Time Limit: 4 s Memory Limit: 256 MB Total points: 100

#12016. 随机函数

統計

作为一名程序语言方向的博士生,九条可怜每天的工作就是和各种各样的程序(函数)打交道。今天,她遇到了一个简洁有趣的问题,于是就把它出成了比赛题目。

众所周知,给定整数 $m$,将 $\{1,\dots,m\}$ 映射到 $\{1, \dots, m\}$ 的函数一共有 $M=m^m$ 个。可怜把这些函数记作 $f_1, \dots, f_M$。

可怜首先从 $[1,M]$ 中(独立等概率地)随机了两个整数 $a,b$,然后从 $[1,m]$ 中(独立等概率地)随机了 $2n$ 个整数 $x_1, \dots, x_n$ 和 $y_1, \dots, y_n$。

现在,可怜想要知道对于每一个 $i \in [1,n]$,$f_{a}(x_i)$ 都等于 $f_b(y_i)$ 的概率,即 $\Pr[\wedge_{i=1}^n f_a(x_i)=f_b(y_i)]$。

输入格式

第一行包含三个整数 $n,m,P (1 \leq n \leq 40, 1 \leq m \leq 10^8, 10^8 < P \leq 10^9)$。

输入保证 $P$ 是一个质数。

输出格式

输出一行一个整数,表示概率对 $P$ 取模后的结果。

样例数据

样例 1 输入

1 2 998244353

样例 1 输出

499122177

样例 2 输入

2 2 998244353

样例 2 输出

686292993

样例 3 输入

10 7 998244353

样例 3 输出

59788847

样例解释

在前两个样例中,概率的真实值分别为 $1/2$ 和 $5/16$。

子任务

子任务一($6$ 分),$1 \leq n,m \leq 5$。

子任务二($21$ 分),$1 \leq n,m \leq 30$。

子任务三($32$ 分),$1 \leq n,m \leq 40$。

子任务四($41$ 分),$1 \leq n \leq 40, 1 \leq m \leq 10^8$。

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.