Q - Phalanx

题目链接:https://vjudge.net/contest/68966#problem/Q

分析:这里的对称并不是指的是关于原矩阵(也就是最大的那一个)主对角线对称,而是对于每一个小的矩阵来说,当前矩阵的对反对角线。

#include<iostream>
#include<string>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stdio.h>
using namespace std;
# define maxn 1000+10
char a[maxn][maxn];
int dp[maxn][maxn];
int n;
int ans;
void  cal(int t1,int t2){
if(t1==1||t2==n){
dp[t1][t2]=1;
return ;
}
int x,y;
x=t1;
y=t2;
while(x>=1&&y<=n&&a[x][t2]==a[t1][y]){
x--;
y++;
}
int temp=t1-x;
if(temp>=dp[t1-1][t2+1]+1)dp[t1][t2]=dp[t1-1][t2+1]+1;
else dp[t1][t2]=temp;
ans=max(ans,dp[t1][t2]);
}
int main()
{
    while(~scanf("%d",&n)&&n)
    {
        getchar();
        for(int i=1; i<=n; i++)
        {
            for(int j=1; j<=n; j++)
            {
                scanf("%c",&a[i][j]);
            }
            getchar();
        }
        memset(dp,0,sizeof(dp));
        ans=1;
        for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
        cal(i,j);
        }
        }
        printf("%d\n",ans);
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/letlifestop/p/10262873.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值