Phalanx (hdu 2859)

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 Description

Today is army day, but the servicemen are busy with the phalanx for the celebration of the 60th anniversary of the PRC.
A phalanx is a matrix of size n*n, each element is a character (a~z or A~Z), standing for the military branch of the servicemen on that position.
For some special requirement it has to find out the size of 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 is symmetrical by the “left-down to right-up” line. The element on the corresponding place should be the same. For example, here is a 3*3 symmetrical matrix:
cbx
cpb
zcc

Input

There are several test cases in the input file. Each case starts with an integer n (0<n<=1000), followed by n lines which has n character. There won’t be any blank spaces between characters or the end of line. The input file is ended with a 0.

Output

Each test case output one line, the size of the maximum symmetrical sub- matrix.

Sample Input

3
abx
cyb
zca
4
zaba
cbab
abbc
cacq
0

Sample Output

3
3

Source

2009 Multi-University Training Contest 5 - Host by NUDT

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

#define N 1100
#define MOD 1000000007
#define met(a, b) memset(a, b, sizeof(a))
#define INF 0x3f3f3f3f

char G[N][N];
int dp[N][N];

int main()
{
    int n;

    while(scanf("%d", &n), n)
    {
        int i, 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;
            else dp[i][j] = i-i1;

            Max = max(Max, dp[i][j]);
        }

        printf("%d\n", Max);
    }
    return 0;
}
时间: 2024-12-21 05:05:47

Phalanx (hdu 2859)的相关文章

Valentine&#39;s Day Round 1001.Ferries Wheel(hdu 5174)解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5174 题目意思:给出 n 个人坐的缆车值,假设有 k 个缆车,缆车值 A[i] 需要满足:A[i−1]<A[i]<A[i+1](1<i<K).现在要求的是,有多少人满足,(他坐的缆车的值 + 他左边缆车的值) % INT_MAX == 他右边缆车的值. 首先好感谢出题者的样例三,否则真的会坑下不少人.即同一部缆车可以坐多个人.由于缆车的值是唯一的,所以可以通过排序先排出缆车的位置.求出

最短路 (HDU 2544)

最短路 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 28836    Accepted Submission(s): 12480 Problem Description 在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt.但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找

BestCoder Round #70 Jam&#39;s math problem(hdu 5615)

Problem Description Jam has a math problem. He just learned factorization. He is trying to factorize ax^2+bx+cax?2??+bx+c into the form of pqx^2+(qk+mp)x+km=(px+k)(qx+m)pqx?2??+(qk+mp)x+km=(px+k)(qx+m). He could only solve the problem in which p,q,m,

RPG的错排 (HDU 2068)

RPG的错排 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6746    Accepted Submission(s): 2738 Problem Description 今年暑假杭电ACM集训队第一次组成女生队,其中有一队叫RPG,但做为集训队成员之一的野骆驼竟然不知道RPG三个人具体是谁谁.RPG给他机会让他猜猜,第一次猜:R是

BestCoder Round #29 1003 (hdu 5172) GTY&#39;s gay friends [线段树 判不同 预处理 好题]

传送门 GTY's gay friends Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 264    Accepted Submission(s): 57 Problem Description GTY has n gay friends. To manage them conveniently, every morning he o

字典树 Trie (HDU 1671)

Problem Description Given a list of phone numbers, determine if it is consistent in the sense that no number is the prefix of another. Let's say the phone catalogue listed these numbers: 1. Emergency 911 2. Alice 97 625 999 3. Bob 91 12 54 26 In this

BestCoder Round #1 1002 项目管理 (HDU 4858)

项目管理 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 738    Accepted Submission(s): 260 Problem Description 我们建造了一个大项目!这个项目有n个节点,用很多边连接起来,并且这个项目是连通的!两个节点间可能有多条边,不过一条边的两端必然是不同的节点.每个节点都有一个能量值. 现在我

Bestcoder13 1003.Find Sequence(hdu 5064) 解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5064 题目意思:给出n个数:a1, a2, ..., an,然后需要从中找出一个最长的序列 b1, b2, ...,  bt.需要满足两个条件(1)b1≤b2≤…≤bt   (2)b2−b1≤b3−b2≤?≤bt−bt−1.求出最大的 t 为多少. 遗留大半年的题目呀呀呀呀~~~~!!!首先非常感谢乌冬子大半年前的指点迷津,呕心沥血想了大半天举出个反例,以便指出我算法的错误.为了纪念这个伟大的人物(

BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)

Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 681    Accepted Submission(s): 280 Problem Description Baby Ming is fond of weight lifting. He has a barbell pole(the