当前位置:网站首页>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;
}
边栏推荐
- Go language loop statement (3 in Lesson 10)
- __ init__ () missing 2 required positive arguments
- redis03——Redis的网络配置与心跳机制
- Redis03 - network configuration and heartbeat mechanism of redis
- 解析互联网时代的创客教育技术
- Delphi SOAP WebService 服务器端多个 SoapDataModule 实现相同的接口方法,接口继承
- Solve the problem of data disorder caused by slow asynchronous interface
- 【微信小程序】协同工作与发布
- Caduceus从未停止创新,去中心化边缘渲染技术让元宇宙不再遥远
- 哈希表(Hash Tabel)
猜你喜欢

MP3是如何诞生的?
![Jerry added the process of turning off the touch module before turning it off [chapter]](/img/28/5e4eb39243a0c973d0b90f76571f9b.png)
Jerry added the process of turning off the touch module before turning it off [chapter]

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

IIC (STM32)

每日一题-LeetCode556-下一个更大元素III-字符串-双指针-next_permutation

Master the use of auto analyze in data warehouse

MongoDB聚合操作总结

How to use concurrentlinkedqueue as a cache queue
![[early knowledge of activities] list of recent activities of livevideostack](/img/14/d2cdae45a18a5bba7ee1ffab903af2.jpg)
[early knowledge of activities] list of recent activities of livevideostack

【活动早知道】LiveVideoStack近期活动一览
随机推荐
Flutter在 release版本,打开后随机白屏不显示内容
如何借助自动化工具落地DevOps
[wechat applet] collaborative work and release
Application practice | Shuhai supply chain construction of data center based on Apache Doris
奋斗正当时,城链科技战略峰会广州站圆满召开
[weekly translation go] how to code in go series articles are online!!
IIC (STM32)
Jerry's ad series MIDI function description [chapter]
Liu Jincheng won the 2022 China e-commerce industry innovation Figure Award
创客思维在高等教育中的启迪作用
minidom 模块写入和解析 XML
Huawei ENSP simulator enables devices of multiple routers to access each other
Cadeus has never stopped innovating. Decentralized edge rendering technology makes the metauniverse no longer far away
Exclusive interview of open source summer | new committer Xie Qijun of Apache iotdb community
MongoDB聚合操作总结
更强的 JsonPath 兼容性及性能测试之2022版(Snack3,Fastjson2,jayway.jsonpath)
Minidom module writes and parses XML
每日一题-LeetCode1200-最小绝对差-数组-排序
2022 version of stronger jsonpath compatibility and performance test (snack3, fastjson2, jayway.jsonpath)
Jerry's ad series MIDI function description [chapter]