luogu#P3126. [USACO15OPEN] Palindromic Paths G
[USACO15OPEN] Palindromic Paths G
题目描述
Farmer John's farm is in the shape of an grid of fields (), each labeled with a letter in the alphabet. For example:
ABCD
BXZX
CDXB
WCBA
Each day, Bessie the cow walks from the upper-left field to the lower-right field, each step taking her either one field to the right or one field downward. Bessie keeps track of the string that she generates during this process, built from the letters she walks across. She gets very disoriented, however, if this string is a palindrome (reading the same forward as backward), since she gets confused about which direction she had walked. Please help Bessie determine the number of distinct routes she can take that correspond to palindromes. Different ways of obtaining the same palindrome count multiple times. Please print your answer modulo 1,000,000,007.
农夫 FJ 的农场是一个 的正方形矩阵(),每一块用一个字母作标记。比如说:
ABCD
BXZX
CDXB
WCBA
某一天,FJ 从农场的左上角走到右下角,当然啦,每次他只能往右或者往下走一格。FJ 把他走过的路径记录下来。现在,请你把他统计一下,所有路径中,回文串的数量(从前往后读和从后往前读一模一样的字符串称为回文串)。
输入格式
The first line of input contains , and the remaining lines contain the
rows of the grid of fields. Each row contains characters that are
in the range A..Z.
第一行包括一个整数 ,表示农场的大小,接下来输入一个 的字母矩阵。
输出格式
Please output the number of distinct palindromic routes Bessie can take,
modulo 1,000,000,007.
输出一个整数,表示回文串的数量。
4
ABCD
BXZX
CDXB
WCBA
12
提示
Bessie can make the following palindromes
1 x "ABCDCBA"
1 x "ABCWCBA"
6 x "ABXZXBA"
4 x "ABXDXBA"