当前位置:网站首页>HDU - 2859 Phalanx(DP)
HDU - 2859 Phalanx(DP)
2022-07-04 21:03:00 【WA_自动机】
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;
}
边栏推荐
- Jerry added the process of turning off the touch module before turning it off [chapter]
- Use of class methods and class variables
- IIC (STM32)
- Interviewer: what is XSS attack?
- How was MP3 born?
- Kubeadm初始化报错:[ERROR CRI]: container runtime is not running
- 创客思维在高等教育中的启迪作用
- [early knowledge of activities] list of recent activities of livevideostack
- [wechat applet] collaborative work and release
- 旋变串判断
猜你喜欢
【LeetCode】17、电话号码的字母组合
Application practice | Shuhai supply chain construction of data center based on Apache Doris
每日一题-LeetCode556-下一个更大元素III-字符串-双指针-next_permutation
一文掌握数仓中auto analyze的使用
Huawei ENSP simulator layer 3 switch
【微信小程序】协同工作与发布
MP3是如何诞生的?
创客思维在高等教育中的启迪作用
Huawei ENSP simulator enables devices of multiple routers to access each other
Maya lamp modeling
随机推荐
Flutter 返回按钮的监听
Jerry's ad series MIDI function description [chapter]
刘锦程荣获2022年度中国电商行业创新人物奖
Go language loop statement (3 in Lesson 10)
CloudCompare&Open3D DBSCAN聚类(非插件式)
Analysis of maker education technology in the Internet Era
为什么说不变模式可以提高性能
[ 每周译Go ] 《How to Code in Go》系列文章上线了!!
Case sharing | integrated construction of data operation and maintenance in the financial industry
如何借助自动化工具落地DevOps
Learning breakout 3 - about energy
TCP shakes hands three times and waves four times. Do you really understand?
GTEST from ignorance to proficient use (2) what is test fixture
Huawei ENSP simulator configures DHCP for router
At the right time, the Guangzhou station of the city chain science and Technology Strategy Summit was successfully held
Enlightenment of maker thinking in Higher Education
解读创客教育中的各类智能化组织发展
Redis has three methods for checking big keys, which are necessary for optimization
A quick start to fastdfs takes you three minutes to upload and download files to the ECS
gtest从一无所知到熟练使用(4)如何用gtest写单元测试