Phalanx

Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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
/*
题意:给你一个n*n的字符矩阵,让你求出,最大的对称矩阵的边长,对角线是从左下角到右上角 初步思路:递推 ,从右上角向下递推,dp[i][j]表示是以(i,j)为左下角的最大对称矩阵的边长,这样就得到状态转移方程:
从(i,j)开始向上,向右遍历,如果相等的长度>dp[i-1][j+1]的话,dp[i][j]=dp[i-1][j+1]+1,否则的话就是
dp[i-1][j+1]; #错误:还在找错误原因
*/
#include <bits/stdc++.h>
using namespace std;
int n;
char s[][];
int dp[][];
int maxn=;
void init(){
memset(dp,,sizeof dp);
maxn=;
}
int main(){
// freopen("in.txt","r",stdin);
while(scanf("%d",&n)!=EOF&&n){
init();
for(int i=;i<=n;i++){
scanf("%s",s[i]+);
}
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(i==||j==n){
dp[i][j]=;
continue;
}
int a=i,b=j;//表示向上向右遍历的长度
while(a>=&&b<=n&&s[a][j]==s[i][b]){
a--;
b++;
}
// cout<<dp[i][j]<<" ";
a=i-a;
if(a>=dp[i-][j+]+){
dp[i][j]=dp[i-][j+]+;
}else{
dp[i][j]=a;
}
maxn=max(dp[i][j],maxn);
}
// cout<<endl;
}
// for(int i=1;i<=n;i++){
// for(int j=1;j<=n;j++){
// cout<<dp[i][j]<<" ";
// }
// cout<<endl;
// }
printf("%d\n",maxn);
}
return ;
}

Phalanx的更多相关文章

  1. HDU2859 Phalanx (动态规划)

    Today is army day, but the servicemen are busy with the phalanx for the celebration of the 60th anni ...

  2. hdu 2859 Phalanx (最大对称子矩阵)

    Problem Description Today is army day, but the servicemen are busy with the phalanx for the celebrat ...

  3. Phalanx (hdu 2859)

    http://acm.hdu.edu.cn/showproblem.php?pid=2859     Time Limit: 10000/5000 MS (Java/Others)    Memory ...

  4. HDU 2859 Phalanx (DP)

    Phalanx Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  5. HDU 2859 Phalanx(对称矩阵 经典dp样例)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2859 Phalanx Time Limit: 10000/5000 MS (Java/Others)  ...

  6. HDU 2859—Phalanx(DP)

    Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description Today i ...

  7. 【学术篇】NOIP2017 d2t3 列队phalanx splay做法

    我可去他的吧.... ==============先胡扯些什么的分割线================== 一道NOIP题我调了一晚上...(其实是因为昨晚没有找到调试的好方法来的说...) 曾经我以 ...

  8. 【HDU - 2859 】Phalanx (dp 最大对称子图)

    Phalanx 先搬翻译 Descriptions: 给你一个矩阵,只由小写或大写字母构成.求出它的最大对称子矩阵的边长. 其中对称矩阵是一个k*k的矩阵,它的元素关于从左下角到右上角的对角线对称.例 ...

  9. HDU 2859 Phalanx (dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2859 给你一个n*n的矩阵,问你最大的对称度是多少(左下右上为对称线) dp[i][j]表示i行j列元 ...

随机推荐

  1. JSP内置对象的实验报告,页面登陆设计

    JSP内置对象的实验报告 一.实验目的: 本实验的目的是让学生掌握怎样在JSP中使用内置对象request.page.response等. 二.实验要求: 编写四个JSP 页面login.jsp.Re ...

  2. linux free命令解读

    $ free -m total used free shared buffers cached Mem: 1002 769 232 0 62 421 -/+ buffers/cache: 286 71 ...

  3. OpenVPN CentOS7 安装部署配置详解

    一 .概念相关 1.vpn 介绍 vpn 虚拟专用网络,是依靠isp和其他的nsp,在公共网络中建立专用的数据通信网络的技术.在vpn中任意两点之间的链接并没有传统的专网所需的端到端的物理链路,而是利 ...

  4. 对Java Web项目中路径的理解

    第一个:文件分隔符 坑比Window.window分隔符 用\;unix采用/.于是用File.separator来跨平台 请注意:这是文件路径.在File f = new File(“c:\\hah ...

  5. jq 通过标签属性匹配标签

    有时候会有这样的需求 在一堆的标签中定位到某个标签去获取值 这时候我们就可以通过使用自定义属性将这一堆标签打上不同的标记 通过属性定位标签了 下面是代码: <input class=" ...

  6. spring <context:annotation-config> 跟 <context:component-scan>诠释及区别

    <context:annotation-config> 和 <context:component-scan>的区别 Difference between <context ...

  7. DataGridView一些常用操作

    SqlConnection conn = new SqlConnection('Server=(local);DataBase=test;User=sa;Pwd=sa'); SqlDataAdapte ...

  8. Socket简单实现数据交互及上传

    声明:本文为原创,如需转载请说明出处:http://www.cnblogs.com/gudu1/p/7669175.html 首先为什么要写这个呢?因为在几个月之前我还使用Socket做一个小项目,而 ...

  9. 学习笔记之CSS样式(选择器背景字体边框绝/相对、固定位置and分层流等)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. linux 守护进程编程

    概述: Daemon运行在后台也称作"后台服务进程". 它是没有控制终端与之相连的进程.它独立于控制终端.通常周期的执行某种任务. 守护进程脱离终端是为了避免进程在执行过程中的信息 ...