F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Rikka with Nash Equilibrium

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 2557    Accepted Submission(s): 1037


Problem Description
Nash Equilibrium is an important concept in game theory.

Rikka and Yuta are playing a simple matrix game. At the beginning of the game, Rikka shows an $n \times m$ integer matrix $A$. And then Yuta needs to choose an integer in $[1,n]$, Rikka needs to choose an integer in $[1,m]$. Let $i$ be Yuta's number and $j$ be Rikka's number, the final score of the game is $A_{i,j}$.

In the remaining part of this statement, we use $(i,j)$ to denote the strategy of Yuta and Rikka.

For example, when $n=m=3$ and matrix $A$ is
\begin{align*}
\begin{bmatrix}
1 & 2 & 1\\
1 & 4 & 3\\
1 & 1 & 1\\
\end{bmatrix}
\end{align*}
If the strategy is $(1,2)$, the score will be $2$; if the strategy is $(2,2)$, the score will be $4$.

A pure strategy Nash equilibrium of this game is a strategy $(x,y)$ which satisfies neither Rikka nor Yuta can make the score higher by changing his(her) strategy unilaterally. Formally, $(x,y)$ is a Nash equilibrium if and only if:
\begin{align*}
\begin{cases}
A_{x,y} \geq A_{i,y} \ \ \forall i \in [1, n] \\
A_{x,y} \geq A_{x,j} \ \ \forall j \in [1,m]
\end{cases}
\end{align*}

In the previous example, there are two pure strategy Nash equilibriums: $(3,1)$ and $(2,2)$.

To make the game more interesting, Rikka wants to construct a matrix $A$ for this game which satisfies the following conditions:
1. Each integer in $[1, nm]$ occurs exactly once in $A$.
2. The game has at most one pure strategy Nash equilibriums.

Now, Rikka wants you to count the number of matrixes with size $n \times m$ which satisfy the conditions.
 

Input
The first line contains a single integer $t(1 \leq t \leq 20)$, the number of the testcases.

The first line of each testcase contains three numbers $n,m$ and $K(1 \leq n,m \leq 80, 1 \leq K \leq 10^9)$.

The input guarantees that there are at most $3$ testcases with $\max(n,m) > 50$.
 

Output
For each testcase, output a single line with a single number: the answer modulo $K$.
 

Sample Input
2 3 3 100 5 5 2333
 

Sample Output
64 1170
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-30 11:17:32, Gzip enabled