#P3713. [BJOI2017] 机动训练
[BJOI2017] 机动训练
Description
Input the island’s terrain grid and compute the sum of weights over all mobility paths, where the weight of a mobility path is the number of mobility paths sharing the same terrain sequence. Output the result modulo .
Input Format
The first line contains two integers , the size of the island.
Then follow lines, each containing characters, describing the island’s terrain.
Output Format
Output a single number, the sum of weights over all mobility paths, modulo .
2 2
.*
*.
72
2 3
.*.
*.*
418
4 4
abba
baab
baab
abba
44512
Hint
Sample Explanation 1
Pairs in square brackets denote a mobility path, with coordinates in the order row, column:
- Terrain sequence
.*: $[(1, 1), (1, 2)],\ [(1, 1), (2, 1)],\ [(2, 2), (2, 1)],\ [(2, 2), (1, 2)]$, paths in total, each with weight , contributing . - Terrain sequence
*.: $[(1, 2), (1, 1)],\ [(2, 1), (1, 1)],\ [(2, 1), (2, 2)],\ [(1, 2), (2, 2)]$, paths in total, each with weight , contributing . - Terrain sequence
..: , paths in total, each with weight , contributing . - Terrain sequence
**: , paths in total, each with weight , contributing . - Terrain sequence
.*.: $[(1, 1), (1, 2), (2, 2)],\ [(1, 1), (2, 1), (2, 2)],\ [(2, 2), (2, 1), (1, 1)],\ [(2, 2), (1, 2), (1, 1)]$, paths in total, each with weight , contributing . - Terrain sequence
*.*: $[(1, 2), (1, 1), (2, 1)],\ [(2, 1), (1, 1), (1, 2)],\ [(1, 2), (2, 2), (2, 1)],\ [(2, 1), (2, 2), (1, 2)]$, paths in total, each with weight , contributing .
Total: .
Sample Explanation 2
- Terrain sequence
.*: paths, each with weight , contributing . - Terrain sequence
*.: paths, each with weight , contributing . - Terrain sequence
..: paths, each with weight , contributing . - Terrain sequence
**: paths, each with weight , contributing . - Terrain sequence
..*: paths, each with weight , contributing . - Terrain sequence
.*.: paths, each with weight , contributing . - Terrain sequence
.**: paths, each with weight , contributing . - Terrain sequence
*..: paths, each with weight , contributing . - Terrain sequence
*.*: paths, each with weight , contributing . - Terrain sequence
**.: paths, each with weight , contributing . - Terrain sequence
.*.*: paths, each with weight , contributing . - Terrain sequence
*.*.: paths, each with weight , contributing .
Total: .
Constraints
- For of the testdata, .
- For of the testdata, .
- For of the testdata, .
- In an additional of the testdata, all terrains are the same.
- For of the testdata, , and the character set consists of uppercase letters, lowercase letters, digits, and
.*.
Translated by ChatGPT 5
京公网安备 11011102002149号