如果size 大于(2,1)位置右上角面那个矩阵(指的是:以(1,2)为左下角的对称子矩阵)的尺寸:dp[1][2],那么
d
p
[
2
]
[
1
]
=
d
[
1
]
[
2
]
+
1
dp[2][1] = d[1][2] + 1
dp[2][1]=d[1][2]+1,
否则的话 d[2][1]就等于在(2,1)位置匹配的对称矩阵的尺寸:size
代码
#include<iostream>#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>#include<string>#include<queue>#include<map>/* #include <unordered_map> */#include<bitset>#include<vector>voidfre(){system("clear"),freopen("A.txt","r",stdin);freopen("Ans.txt","w",stdout);}voidFre(){system("clear"),freopen("A.txt","r",stdin);}#define ios ios::sync_with_stdio(false)#define Pi acos(-1)#define pb push_back#define fi first#define se second#define ll long long#define ull unsigned long long#define db double#define Pir pair<int, int>#define PIR pair<Pir, Pir>#define m_p make_pair#define INF 0x3f3f3f3f#define esp 1e-7#define mod (ll)(1e9 + 7)#define for_(i, s, e) for(int i = (ll)(s); i <= (ll)(e); i ++)#define rep_(i, e, s) for(int i = (ll)(e); i >= (ll)(s); i --)#define sc scanf#define pr printf#define sd(a) scanf("%d", &a)#define ss(a) scanf("%s", a)
using namespace std;#define Max(a, b, c, d) max(max(a, b), max(c, d));#define Min(a, b, c, d) min(min(a, b), min(c, d));constint mxn =1005;int dp[mxn][mxn];char mz[mxn][mxn];intmain(){/* fre(); */int n;while(sd(n)&& n){for_(i,0, n -1)ss(mz[i]);int mx =0;for_(i,0, n -1)for_(j,0, n -1){if(i ==0|| j == n -1)
dp[i][j]=1;int x = i, y = j;while(x >=0&& y < n && mz[x][j]== mz[i][y])
x --, y ++;int size = i - x;if(size > dp[i -1][j +1]) dp[i][j]= dp[i -1][j +1]+1;else dp[i][j]= size;
mx =max(mx, dp[i][j]);}pr("%d\n", mx);}return0;}