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

题意:找到最大对称的矩阵

每次只需求最外面一层对称个数sum,再和右上角对称矩阵大小加一取最小就行,就求出当前小矩阵的最大对称矩阵。最后取个所有对称矩阵大小的最大值就行。

dp[i][j] = min(sum,dp[i-1][j+1]+1);

#include <cstdio>
#include <map>
#include <iostream>
#include<cstring>
#include<bits/stdc++.h>
#define ll long long int
#define M 6
using namespace std;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int moth[]={,,,,,,,,,,,,};
int dir[][]={, ,, ,-, ,,-};
int dirs[][]={, ,, ,-, ,,-, -,- ,-, ,,- ,,};
const int inf=0x3f3f3f3f;
const ll mod=1e9+;
int n;
char G[][];
int dp[][];
int main(){
ios::sync_with_stdio(false);
while(cin>>n&&n){
char a;
for(int i=;i<=n;i++)
for(int j=;j<=n;j++){
cin>>a;
if(a>='A'&&a<='Z')
a+=;
G[i][j]=a;
}
memset(dp,,sizeof(dp));
int ans=-inf;
for(int i=;i<=n;i++)
for(int j=n;j>=;j--){
int x=i; int y=j;
int sum=;
while(x>=&&y<=n&&G[x][j]==G[i][y]){
x--; y++;
sum++;
}
dp[i][j]=min(sum,dp[i-][j+]+);
ans=max(ans,dp[i][j]);
}
cout<<ans<<endl;
}
}

hdu 2859 Phalanx (最大对称子矩阵)的更多相关文章

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

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

  2. hdu(2859)——Phalanx(dp)

    题意: 如今有一个n*n的矩阵,然后每一个格子中都有一个字母(大写或小写组成).然后询问你如今最大的对称子矩阵的边长是多少.注意这里的对角线是从左下角到右上角上去的. 思路: 这道题我自己写出了dp的 ...

  3. HDU 2859 Phalanx(二维DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2859 题目大意:对称矩阵是这样的矩阵,它由“左下到右”线对称. 相应位置的元素应该相同. 例如,这里是 ...

  4. HDU 2859 Phalanx (dp)

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

  5. HDU 2859—Phalanx(DP)

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

  6. HDU 2859 Phalanx (DP)

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

  7. HDU 2859 Phalanx

    简单二维dp.o(n^3)效率过的.不知道有没有o(n^2)的解法. 为了方便点,先左右交换一下. dp[i][j]表示以[i,j]为左上角的最大对称矩阵长度 那么dp[i][j]=min(Max,d ...

  8. HDU 2859 Phalanx ——(DP)

    感觉是个n^3的dp,只是可能上界比较松吧..转移见代码.值得注意的一个地方是如果n是1,那么在for里面是不会更新答案的,因此ans要初始化为1. 代码如下: #include <stdio. ...

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

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

随机推荐

  1. fork分支与源分支同步代码

    最进软件工程课程要团队开发做个网站项目,于是我在团队里推了使用github这种网站来协同开发,但是出现了个问题:fork后的代码无法 与源分支代码同步,导致fork分支的代码只有自己写的那部分,而不是 ...

  2. git fetch 和git pull 的差别

    1.git fetch 相当于是从远程获取最新到本地,不会自动merge,如下指令: git fetch orgin master //将远程仓库的master分支下载到本地当前branch中 git ...

  3. jQ append 添加html 及字符串拼接

    如图,我要拼接这样一段html: 点击下边添加按钮,不断添加这段Html html: <div class="x_addtable"> <div class=&q ...

  4. python设计模式第二十三天【状态模式】

    1.应用场景 (1)通过改变对象的内部状态从而改变对象的行为,一般表现为状态的顺序执行 2.代码实现 #!/usr/bin/env python #!_*_ coding:UTF-8 _*_ from ...

  5. qtp10 安装笔记

    windows10系统安装QTP 10 1 QTP10 程序文件夹下,找到“setup”双击它运行安装程序-点击 否 继续安装 2 安装必要组件 3 下一步 选择安装程序目录-安装插件 直到完成安装 ...

  6. Bootstrap之图片展示界面Demo

    代码:(使用模板引擎freemarker) <!DOCTYPE html> <html> <head> <title>图片</title> ...

  7. iis7.0 发生未知 FastCGI错误,错误代码 0x8007010b 的解决办法

    错误提示 修改该网站所对应的应用程序池 进程模型->标识 修改为:LocalSystem

  8. freemarker 设置中文

    在web中添加一段代码 <servlet> <servlet-name>freemarker</servlet-name> <servlet-class> ...

  9. react 自我小计

    1.react中的方法调用,在onClick事件中不需要加小括号. <button onClick={this.show}>方法的调用</button> show(){ con ...

  10. HTML5 ----- deviceorientation API

    当我们把设备举到面前,就是坐公交车时玩手机的状态,手机的宽度(水平方向)就是X轴,从左向右依次变大:手机的高度(垂直方向)就是y轴,从下到上依次变大: 眼光盯着屏幕,我们的视线就是Z轴,离我们的眼睛越 ...