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. 匹配替换第n个字符串

    var name = "questions[0][question]",i=0; name.replace(/\[.+?\]/g, function(match, pos, ori ...

  2. [js高手之路] html5 canvas系列教程 - 文本样式(strokeText,fillText,measureText,textAlign,textBaseline)

    接着上文线条样式[js高手之路] html5 canvas系列教程 - 线条样式(lineWidth,lineCap,lineJoin,setLineDash)继续. canvas提供两种输出文本的方 ...

  3. 代码与编程(java基础)

    代码与编程(面试与笔试java) 1.写一个Singleton出来 Singleton模式主要作用是保证在Java应用程序中,一个类Class只有一个实例存在. 一般Singleton模式通常有几种种 ...

  4. Huge Mission

    Huge Mission Problem Description Oaiei is busy working with his graduation design recently. If he ca ...

  5. Android UI 笔记

    EditText中添加小图标 <TextView android:layout_width="wrap_content" android:layout_height=&quo ...

  6. Hadoop(四)HDFS集群详解

    前言 前面几篇简单介绍了什么是大数据和Hadoop,也说了怎么搭建最简单的伪分布式和全分布式的hadoop集群.接下来这篇我详细的分享一下HDFS. HDFS前言: 设计思想:(分而治之)将大文件.大 ...

  7. ASP.NET/MVC 配置log4net启用写错误日志功能

    <?xml version="1.0" encoding="utf-8"?> <!-- 有关如何配置 ASP.NET 应用程序的详细信息,请访 ...

  8. dotweb框架之旅 [一] - HelloWorld

    一直想着,要系统性的写一些dotweb使用的文章,之前拖延了不少时间,今天,下定决定,算是正式的开始,也请大家一起监督. dotweb,是一款追求简约大方的go web框架,正如其github项目主页 ...

  9. iOS中单例需要注意的

    单例模式怎么定义的,可能在不同的语言,不同的书中不完全一样,但是概况开来都应该是:一个类有且仅有一个实例,并且自行实例化向整个系统提供. 因此,首先你可能需要确定你是真的需要一个单例类,还是说仅仅是需 ...

  10. ReactiveCocoa_v2.5 源码解析之架构总览

    ReactiveCocoa 是一个 iOS 中的函数式响应式编程框架,它受 Functional Reactive Programming 的启发,是 Justin Spahr-Summers 和 J ...