当前位置:网站首页>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;
}
边栏推荐
- Flutter WebView示例
- MYSQL 用!=查询不出等于null的数据,解决办法
- 【LeetCode】17、电话号码的字母组合
- 应用实践 | 蜀海供应链基于 Apache Doris 的数据中台建设
- Redis 排查大 key 的3种方法,优化必备
- Jerry's ad series MIDI function description [chapter]
- Day24: file system
- Jerry's ad series MIDI function description [chapter]
- 开源之夏专访|Apache IoTDB社区 新晋Committer谢其骏
- Flutter在 release版本,打开后随机白屏不显示内容
猜你喜欢
![[leetcode] 17. Letter combination of telephone number](/img/be/7f456c092f7cda5ebabc2f1cce292e.png)
[leetcode] 17. Letter combination of telephone number

Case sharing | integrated construction of data operation and maintenance in the financial industry

【LeetCode】17、电话号码的字母组合

输入的查询SQL语句,是如何执行的?

Analyzing the maker space contained in steam Education

每日一题-LeetCode1200-最小绝对差-数组-排序
![Jerry's ad series MIDI function description [chapter]](/img/d7/348d85eb9f69ffd75612eeba56b16e.png)
Jerry's ad series MIDI function description [chapter]
![Jerry's ad series MIDI function description [chapter]](/img/28/e0f9b41db597ff3288af431c677001.png)
Jerry's ad series MIDI function description [chapter]

【公开课预告】:视频质量评价基础与实践
![Compréhension approfondie du symbole [langue C]](/img/4b/26cf10baa29eeff08101dcbbb673a2.png)
Compréhension approfondie du symbole [langue C]
随机推荐
Kubeadm初始化报错:[ERROR CRI]: container runtime is not running
Liu Jincheng won the 2022 China e-commerce industry innovation Figure Award
Day24: file system
Can be displayed in CAD but not displayed in print
Case sharing | integrated construction of data operation and maintenance in the financial industry
Bookmark
时空预测3-graph transformer
redis03——Redis的网络配置与心跳机制
TCP三次握手,四次挥手,你真的了解吗?
redis RDB AOF
AcWing 2022 每日一题
Master the use of auto analyze in data warehouse
Redis transaction
Delphi SOAP WebService 服务器端多个 SoapDataModule 实现相同的接口方法,接口继承
QT—绘制其他问题
GTEST from ignorance to proficient use (2) what is test fixture
文件读取写入
In the release version, the random white screen does not display the content after opening the shutter
Redis bloom filter
Flutter在 release版本,打开后随机白屏不显示内容