CF1080E Sonya and Matrix Beauty
题目描述
一句话题意:给定一个 $n \times m$ 的字符矩阵,请求出有多少个子矩阵在重排子矩阵每一行的字符后,使得子矩阵的每行每列都是回文串。
Sonya 最近过了生日,她收到一个 $n \times m$ 的字符矩阵。
我们称一个子矩阵是美丽的,当且仅当在重新排列这个子矩阵每一行的字符后,使得这个子矩阵的每一行每一列都是回文串。
Sonya 想要知道这个矩阵中有几个子矩阵是美丽的。
输入格式
第一行两个整数 $n,m(1 \leq m,n \leq 250)$,意义如上文所述。
接下来 $n$ 行一行 $m$ 个字符,表示这个子矩阵每一行的字符。
输出格式
一行一个整数,表示美丽的子矩阵数目。
说明/提示
In the first example, the following submatrixes are beautiful: $ ((1, 1), (1, 1)); ((1, 2), (1, 2)); $ $ ((1, 3), (1, 3)); ((1, 1), (1, 3)) $ .
In the second example, all submatrixes that consist of one element and the following are beautiful: $ ((1, 1), (2, 1)); $ $ ((1, 1), (1, 3)); ((2, 1), (2, 3)); ((1, 1), (2, 3)); ((2, 1), (2, 2)) $ .
Some of the beautiful submatrixes are: $ ((1, 1), (1, 5)); ((1, 2), (3, 4)); $ $ ((1, 1), (3, 5)) $ .
The submatrix $ ((1, 1), (3, 5)) $ is beautiful since it can be reordered as:
`
accca
aabaa
accca
`In such a matrix every row and every column form palindromes.
accca
aabaa
accca
`In such a matrix every row and every column form palindromes.