#P4472. [BJWC2018] 八维
[BJWC2018] 八维
Description
We infinitely tile a character matrix with rows and columns to obtain an infinite character matrix. For example, for the following matrix:
$$\begin{aligned} & \verb!honi! \\ & \verb!hsin! \\ \end{aligned}$$we can tile it infinitely to get
$$\begin{aligned} & \verb!...honihonihonihoni...! \\ & \verb!...hsinhsinhsinhsin...! \\ & \verb!...honihonihonihoni...! \\ & \verb!...hsinhsinhsinhsin...! \\ \end{aligned}$$We consider the matrix to be 8-connected. 8-connected means each position in the matrix is adjacent to the positions above, below, left, right, and the four diagonals (upper-left, upper-right, lower-left, lower-right). Therefore, starting from any position in the matrix, you can extend infinitely along any one of the eight directions.
If we uniformly at random choose one position and one direction, then starting from this position and going along this direction, we take consecutive characters to form a string. What is the probability that two such operations produce identical strings? (Assume any position is equally likely and any direction is equally likely.)
Input Format
The first line contains three integers .
The next lines each contain a string of length consisting of lowercase English letters, forming the character matrix. It is guaranteed that at least two different characters appear in the matrix.
Output Format
Output one line containing a reduced fraction representing the probability.
1 2 2
ab
5/16
3 3 10
ban
ana
nab
2/27
Hint
【Sample Explanation】
In Sample 1, there are possibilities for one operation in total. The probability of obtaining \verb!aa! is , the probability of obtaining \verb!ab! is , the probability of obtaining \verb!bb! is , and the probability of obtaining \verb!ba! is . The probability that the results of two operations are the same is .
【Constraints】
- For of the testdata: , .
- For of the testdata: .
- For of the testdata: , .
Translated by ChatGPT 5
京公网安备 11011102002149号