HDU 4618 palindrome sub-array (maximum palindrome matrix)

Source: Internet
Author: User
Palindrome sub-array

Time Limit: 3000/1000 MS (Java/others) memory limit: 65535/32768 K (Java/Others)
Total submission (s): 162 accepted submission (s): 72


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

15 101 2 3 3 2 4 5 6 7 81 2 3 3 3 2 5 6 7 81 2 3 3 2 4 5 6 7 81 2 3 3 2 4 5 6 7 81 2 3 9 10 4 5 6 7 8


Sample output

 
4


Source2013 multi-university training Contest 2


Recommendzhuyuanchen520 direct violence, but pay attention to the break to prevent timeout! No technical skills!

# Include <iostream> # include <string. h> # include <stdio. h ># include <algorithm> using namespace STD; int map [330] [330]; int rec [330]; int n, m; int ans; int is_ OK (int I, int J, int Len) {int K = 0; Len --; while (k <Len) {If (Map [I] [J + k]! = Map [I] [J + Len]) return 0; k ++, Len --;} return 1;} int is_ OK _ver (int I, Int J, int Len) {int K = I + len-1; while (I <k) {If (Map [I] [J]! = Map [k] [J]) return 0; I ++, k --;} return 1;} int is_matrix (int I, Int J, int Len) {int K, r; For (k = 0; k <Len; k ++) {If (! Is_ OK (I + k, J, Len) return 0; If (! Is_ OK _ver (I, j + k, Len) return 0;} return 1;} int find_ans (int I, Int J) {int P = n-I, Q = m-J, Len; Len = P <q? P: Q; If (ANS> = Len) return 0; while (LEN> ans) {If (is_matrix (I, j, Len) {ans = Len; return 0;} Len --;} return 1;} int main () {int T, I, J, K; scanf ("% d", & T ); while (t --) {ans = 1; scanf ("% d", & N, & M); for (I = 0; I <n; I ++) for (j = 0; j <m; j ++) scanf ("% d", & map [I] [J]); for (I = 0; I <n; I ++) for (j = 0; j <m; j ++) {find_ans (I, j) ;} printf ("% d \ n ", ans);} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.