Phalanx

Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 3093 Accepted Submission(s): 1510

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

Recommend

gaojie

题意:找最大对称子矩阵(沿用上角到左下角的对角线对称)。

题解:dp遍历每一个点,比较这一个点所在的列上边和所在行的右边对称的数目,如果大于dp[i-1][j+1],则dp[i][j] = dp[i-1][j+1] + 1,否则等于对称的数目。

#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <cstring>
#include <cmath> using namespace std; const int maxn = 1050; char s[maxn][maxn];
int dp[maxn][maxn]; int main()
{
int n,i,j,Max,a,b;
while(scanf("%d",&n)!=EOF&&n)
{
for(i=0;i<n;i++)
scanf("%s",s[i]);
Max = 0;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i==0||j==n-1)
{
dp[i][j] = 1;
}
else
{
a = i;
b = j;
while(a>=0&&b<n&&s[a][j] == s[i][b])
{
a--;
b++;
}
if(i-a>=dp[i-1][j+1] + 1)
dp[i][j] = dp[i-1][j+1] + 1;
else
dp[i][j] = i - a;
}
Max = max(Max,dp[i][j]);
}
}
printf("%d\n",Max);
}
return 0;
}

HDU-2859_Phalanx的更多相关文章

  1. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  2. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  3. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  4. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  5. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  6. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  7. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  8. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

  9. hdu 4329

    problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟  a.     p(r)=   R'/i   rel(r)=(1||0)  R ...

  10. HDU 2586

    http://acm.hdu.edu.cn/showproblem.php?pid=2586 题意:求最近祖先节点的权值和 思路:LCA Tarjan算法 #include <stdio.h&g ...

随机推荐

  1. Python之常用文件操作

    Python之常用文件操作

  2. python基础--包、logging、hashlib、openpyxl、深浅拷贝

    包:它是一系列模块文件的结合体,表现形式就是一个文件夹,该文件夹内部通常会有一个__init__.py文件,包的本质还是一个模块. 首次导入包:(在导入语句中中 . 号的左边肯定是一个包(文件夹)) ...

  3. Leetcode665.Non-decreasing Array非递减数组

    给定一个长度为 n 的整数数组,你的任务是判断在最多改变 1 个元素的情况下,该数组能否变成一个非递减数列. 我们是这样定义一个非递减数列的: 对于数组中所有的 i (1 <= i < n ...

  4. loadrunner录制脚本时登录密码转md5

    在录制用户注册登录脚本时,常常会遇到web程序对用户密码进行加密处理.在很多时候采用的加密方式为MD5. 这时有两种处理方式: 一.所有用户采用同一密码 例如:每个用户名的密码都为e10adc3949 ...

  5. LintCode_133 最长单词

    题目 给一个词典,找出其中所有最长的单词. 样例 在词典 { "dog", "google", "facebook", "inte ...

  6. LintCode_173 链表插入排序

    题目 用插入排序对链表排序 样例 Given 1->3->2->0->null, return 0->1->2->3->null C++代码 ListN ...

  7. Linux C/C++开发

    首先就是要熟练在vim里面写代码,其实就是没有提示和自动补全了,这个问题并不大. 我服务器gcc版本是4.8.5,所以就按照这个来了 https://gcc.gnu.org/onlinedocs/gc ...

  8. KiCad 工程用 Git 管理需要忽略哪些文件?

    KiCAD 工程用 Git 管理需要忽略哪些文件? KiCAD 使用的 文本格式,天生可以用 Git 来管理. 但是并非所有文件需要使用 Git 管理,以下文件可以忽略. *.bak fp-info- ...

  9. IOS开发基础篇--CAShapeLayer的strokeStart和strokeEnd属性

    http://blog.csdn.net/yixiangboy/article/details/50662704 一.案例演示 最近有一个小需求,就是要做一个圆形进度条,大概样子如下: . 在不知道有 ...

  10. PHP 从 MongoDb 中查询数据怎么样实现

    一.软件环境(版本非必须) php v5.6 扩展:MongoDB nginx v1.11 mongodb v3.2 note: 必须安装MongoDB扩展 二.连接 $client = new Mo ...