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. 高并发之API接口限流

    在开发高并发系统时有三把利器用来保护系统:缓存.降级和限流 缓存 缓存的目的是提升系统访问速度和增大系统处理容量 降级 降级是当服务出现问题或者影响到核心流程时,需要暂时屏蔽掉,待高峰或者问题解决后再 ...

  2. org.elasticsearch.client.transport.NoNodeAvailableException

    SpringBoot连接elasticsearch异常 2018-09-11 16:03:43.692 ERROR 8684 --- [ main] o.s.boot.SpringApplicatio ...

  3. java使用顺序存储实现队列

    详细连接  https://blog.csdn.net/ljxbbss/article/details/78135993 操作系统:当电脑卡的时候,如果不停点击,还是卡死,最后终于电脑又好了以后,操作 ...

  4. phpstorm显示页面不停的在indexing转圈中,并且文件名还一直在刷新

    打开 File下的 Invalidate Caches / Restart...下的 Invalidate and Restart. 便可以了 ......

  5. python之路--JavaScript

    一. JavaScript概述 ECMAScript和JavaScript的关系 1996年11月,JavaScript的创造者--Netscape公司,希望这门语言能成为国际化标准,于是决定将Jav ...

  6. Java线程的5种状态及切换(透彻讲解)-京东面试

    一.Thread的几个重要方法: 我们先了解一下Thread的几个重要方法. a.start()方法,开始执行该线程:b.stop()方法,强制结束该线程执行:c.join方法,等待该线程结束.d.s ...

  7. 常见IT工具软件总结

    1. 阿里云在线迁移服务 2.智能媒体管理 格式转换 业务域名管理 1. 每个业务有一个英文单词, 1. 每个 git 的命名应该是 chgg-业务英文-种类 2. 例如 chgg-plant-api ...

  8. How to install Lion on PC

    open 'InstallESD.dmg' open '/Volumes/Mac OS X Install ESD/BaseSystem.dmg' rm '/Volumes/Mac OS X Base ...

  9. Nginx lingering_close延迟关闭

    L:130

  10. 学习Linux系统的态度及技巧

    Linux作为一种简单快捷的操作系统,现在被广泛的应用.也适合越来越多的计算机爱好者学习和使用.但是对于Linux很多人可能认为很难,觉得它很神秘,从而对其避而远之,但事实真的是这样么?linux真的 ...