# Phalanx (Hdu 2859)

Source: Internet
Author: User

http://acm.hdu.edu.cn/showproblem.php?pid=2859   Time limit:10000/5000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 996 Accepted Submission (s): 468

problem DescriptionToday is Army day, but the servicemen was busy with the Phalanx for the celebration of the 60th anniversary of the PRC .
a phalanx is a matrix of size n*n with each element being a character (a~z or a~z), standing for the military branch of the S Ervicemen on that position.
For some special requirement it had to find out the size of the the max symmetrical sub-array. And with no doubt, the Central Military Committee gave this task to Alpcs.
a symmetrical matrix is such a matrix that it's symmetrical by the ' Left-down to right-up ' line. The element on the corresponding place should is the same. For example, this is a 3*3 symmetrical matrix:
CBX
CPB
ZCC
InputThere is several test cases in the input file. Each case is starts with a integer n (0<n<=1000), followed by n lines which have n character. There won ' t is any blank spaces between characters or the end of line. The input file is ended with a 0.
OutputEach test case is output one line, the size of the maximum symmetrical Sub-matrix.
Sample Input3abxcybzca4zabacbababbccacq0
Sample Output -
Sourcemulti-university Training Contest 5-host by Nudt

`#include <cstdio>#include<cstring>#include<iostream>#include<cmath>#include<vector>#include<algorithm>#include<string>using namespacestd;#defineN 1100#defineMOD 1000000007#defineMet (A, b) memset (A, B, sizeof (a))#defineINF 0x3f3f3f3fCharG[n][n];intDp[n][n];intMain () {intN;  while(SCANF ("%d", &N), N) {intI, J, I1, J1, max=1; Met (G,0); Met (DP,0);  for(i=0; i<n; i++) scanf ("%s", G[i]);  for(i=0; i<n; i++)         for(j=0; j<n; J + +)        {            if(i==0|| j==n-1) {Dp[i][j]=1; Continue; } i1=i, j1=J;  while(J1<n && i1>=0&& g[i1][j]==g[i][j1]) I1--, j1++; if((I-I1) >=dp[i-1][j+1]+1) Dp[i][j] = dp[i-1][j+1] +1; ElseDP[I][J] = iI1; Max=Max (max, dp[i][j]); } printf ("%d\n", Max); }    return 0;}`

Phalanx (Hdu 2859)

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.