当前位置:网站首页>HDU - 2859 Phalanx(DP)
HDU - 2859 Phalanx(DP)
2022-07-04 21:50:00 【WA_ automata】
HDU - 2859 Phalanx
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
#include<iostream>
#include<cstring>
using namespace std;
const int N = 1010;
char s[N][N];
int dp[N][N];
int main()
{
int n;
while(cin>>n,n)
{
memset(dp,0,sizeof dp);
for(int i=1;i<=n;i++) cin>>(s[i]+1);
int ans=1;
for(int i=1;i<=n;i++)
for(int j=n;j>=1;j--)
{
dp[i][j]=1;
if(i==1||j==n) continue;
int l=dp[i-1][j+1];
for(int k=1;k<=l;k++)
if(s[i-k][j]==s[i][j+k]) dp[i][j]++;
else break;
ans=max(ans,dp[i][j]);
}
cout<<ans<<endl;
}
return 0;
}
边栏推荐
- Lambdaquerywrapper usage
- [leetcode] 17. Letter combination of telephone number
- SolidWorks工程图添加材料明细表的操作
- Three or two things about the actual combat of OMS system
- CloudCompare&Open3D DBSCAN聚类(非插件式)
- Use of redis publish subscription
- Le module minidom écrit et analyse XML
- 什么是商业智能(BI),就看这篇文章足够了
- [buuctf.reverse] 151_ [FlareOn6]DnsChess
- Bookmark
猜你喜欢

Redis03 - network configuration and heartbeat mechanism of redis
![[early knowledge of activities] list of recent activities of livevideostack](/img/14/d2cdae45a18a5bba7ee1ffab903af2.jpg)
[early knowledge of activities] list of recent activities of livevideostack

【公开课预告】:视频质量评价基础与实践

QT - plot other problems

ArcGIS 10.2.2 | solution to the failure of ArcGIS license server to start

历史最全混合专家(MOE)模型相关精选论文、系统、应用整理分享

【C語言】符號的深度理解

Redis has three methods for checking big keys, which are necessary for optimization
![[C language] deep understanding of symbols](/img/4b/26cf10baa29eeff08101dcbbb673a2.png)
[C language] deep understanding of symbols

CloudCompare&Open3D DBSCAN聚类(非插件式)
随机推荐
OMS系统实战的三两事
什么是商业智能(BI),就看这篇文章足够了
【公开课预告】:视频质量评价基础与实践
gtest从一无所知到熟练使用(3)什么是test suite和test case
迈动互联中标北京人寿保险
Cadeus has never stopped innovating. Decentralized edge rendering technology makes the metauniverse no longer far away
Can be displayed in CAD but not displayed in print
numpy vstack 和 column_stack
股票开户流程是什么?使用同花顺手机炒股软件安全吗?
PostgreSQL基本结构——表
Interviewer: what is XSS attack?
Super detailed tutorial, an introduction to istio Architecture Principle and practical application
Enlightenment of maker thinking in Higher Education
Kubeadm初始化报错:[ERROR CRI]: container runtime is not running
【活动早知道】LiveVideoStack近期活动一览
GTEST from ignorance to skillful use (1) GTEST installation
SolidWorks工程图添加材料明细表的操作
创客思维在高等教育中的启迪作用
Lambdaquerywrapper usage
ArcGIS 10.2.2 | solution to the failure of ArcGIS license server to start