CF570E.Pig and Palindromes

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Peppa the Pig was walking and walked into the forest. What a strange coincidence! The forest has the shape of a rectangle, consisting of nn rows and mm columns. We enumerate the rows of the rectangle from top to bottom with numbers from 11 to nn , and the columns — from left to right with numbers from 11 to mm . Let's denote the cell at the intersection of the rr -th row and the cc -th column as (r,c)(r,c) .

Initially the pig stands in cell (1,1)(1,1) , and in the end she wants to be in cell (n,m)(n,m) . Since the pig is in a hurry to get home, she can go from cell (r,c)(r,c) , only to either cell (r+1,c)(r+1,c) or (r,c+1)(r,c+1) . She cannot leave the forest.

The forest, where the pig is, is very unusual. Some cells of the forest similar to each other, and some look very different. Peppa enjoys taking pictures and at every step she takes a picture of the cell where she is now. The path through the forest is considered to be beautiful if photographs taken on her way, can be viewed in both forward and in reverse order, showing the same sequence of photos. More formally, the line formed by the cells in order of visiting should be a palindrome (you can read a formal definition of a palindrome in the previous problem).

Count the number of beautiful paths from cell (1,1)(1,1) to cell (n,m)(n,m) . Since this number can be very large, determine the remainder after dividing it by 109+710^{9}+7 .

输入格式

The first line contains two integers n,mn,m ( 1<=n,m<=5001<=n,m<=500 ) — the height and width of the field.

Each of the following nn lines contains mm lowercase English letters identifying the types of cells of the forest. Identical cells are represented by identical letters, different cells are represented by different letters.

输出格式

Print a single integer — the number of beautiful paths modulo 109+710^{9}+7 .

输入输出样例

  • 输入#1

    3 4
    aaab
    baaa
    abba
    

    输出#1

    3

说明/提示

Picture illustrating possibilities for the sample test.

首页