Problem Description
A palindrome sequence is a sequence which is as same as its reversed order. For example, 1 2 3 2 1 is a palindrome sequence, but 1 2 3 2 2 is not. Given a 2-D array of N rows and M columns, your task is to find a maximum sub-array of P rows and P columns, of which each row and each column is a palindrome sequence.
Input
The first line of input contains only one integer, T, the number of test cases. Following T blocks, each block describe one test case.
There is two integers N, M (1<=N, M<=300) separated by one white space in the first line of each block, representing the size of the 2-D array.
Then N lines follow, each line contains M integers separated by white spaces, representing the elements of the 2-D array. All the elements in the 2-D array will be larger than 0 and no more than 31415926.
Output
For each test case, output P only, the size of the maximum sub-array that you need to find.
Sample Input
1
5 10
1 2 3 3 2 4 5 6 7 8
1 2 3 3 2 4 5 6 7 8
1 2 3 3 2 4 5 6 7 8
1 2 3 3 2 4 5 6 7 8
1 2 3 9 10 4 5 6 7 8
Sample Output
4
不知道你用什么语言,所以说一下思路吧,这个思路是我自己想的,可能不是很简便,但是根据题目的数据量,应该ac是没有问题的。
首先,回文数包含2种,一种是奇数长度的,一种是偶数长度的,然后我的思路是给每一个数字进行校验,得出他的最大子阵列。
比如从第一行开始,从1开始,向两边发散,限制条件是碰到边界或者找不到相同的数字,1向左碰到边界,所以这里结束,返回1,也就是说最大子阵列是1.
这是奇数位的判断,当然,偶数位就是从当前2位开始,从两边发散,直到无法匹配,不过,得在之前加个判断条件,也就是当前位和后一位相等。
所以,我们把这个功能写成一个函数,参数就应该是当前的数组下标和每一行的最大宽度(防越界),具体实现就是以上所写的思路。
之后,我们便可以用这个函数对于测试用例每一行来进行测试,这个用循环便可以很轻松的搞定了。
纯手打,望采纳。。。。。。