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. 使用uni-app(Vue.js)创建运行微信小程序项目步骤

    使用uni-app(Vue.js)开发微信小程序项目步骤 1. 新建一个uni-app项目   创建完成后的目录结构 2. 打开微信小程序开发工具端的端口调试功能 3. 运行创建的项目 效果

  2. [BZOJ3990][SDOI2015][LOJ#2181]-排序

    说实话,这个题真好(?) <BZOJ题面> <LOJ题面> 看到这个题,一时没有思路 但是 我想到了一个错解:归并 这个题真的有一点把我们的思路往归并上引 于是WA10 诶?我 ...

  3. 从零开始Android逆向教程(二)——什么是Xposed

    前言在阅读本文之前,假设你的手机已经root,并且已经成功安装好了 XposedInstaller. Xposed是什么?       Xposed 是一个 Android 平台上的动态劫持框架,通过 ...

  4. birt运行环境

    1.下载 http://pan.baidu.com/s/1nvhz5wt 2.解压birt-runtime-4.6.0-20160607.zip 将WebViewerExample更名为birt,复制 ...

  5. java-Map-system

    一 概述 0--星期日1--星期一... 有对应关系,对应关系的一方是有序的数字,可以将数字作为角标. public String getWeek(int num){ if(num<0 || n ...

  6. TP5.1 首页路由

    把自带的return 删了

  7. C# dataGridView_CellValueChanged事件

    C# 输入完以后立即更新缓冲区(DataGridView CheckBox列checked变化后就触发CellValueChanged事件) 在DataGridView添加如下的事件( Current ...

  8. 荷畔微风 - 在函数计算FunctionCompute中使用WebAssembly

    WebAssembly 是一种新的W3C规范,无需插件可以在所有现代浏览器中实现近乎原生代码的性能.同时由于 WebAssembly 运行在轻量级的沙箱虚拟机上,在安全.可移植性上比原生进程更加具备优 ...

  9. Scrollerview与listview或者gridview发生冲突

    滑动冲突说实在的就是子view的滑动事件与父view的滑动事件的监听都在同时触发,而导致的activity的点击事件或者布局出问题 常见的就有Scrollerview与Scrollerview与lis ...

  10. 【eclipse】解决:eclipse或STS运行maven工程出现Missing artifact jdk.tools:jdk.tools:jar:1.7问题

    eclipse或STS运行maven工程出现Missing artifact jdk.tools:jdk.tools:jar:1.7问题 最近项目中使用到大数据平台,代码中应用了hbase-clien ...