以为是很高端的dp呢,谁知道直接暴力就过了,本来还想说水呢,yf说好歹这是多校联赛的题,就没标水
#include"stdio.h"
#include"string.h"
#define N 301
int n,m;
int map[N][N];
int min(int a,int b)
{
return a<b?a:b;
}
int fun(int t)
{
int f;
int i,j;
int x,y;
int a,b;
for(i=1;i+t-1<=n;i++)
{
for(j=1;j+t-1<=m;j++)
{
f=0;
x=i;y=i+t-1;
while(x<=y)
{
a=j;b=j+t-1;
while(a<=b)
{
if(map[x][a]!=map[x][b])break;
a++;b--;
}
if(a<=b)break;
x++;
}
if(x<=y){f=0;continue;}
else f=1;
a=j;b=j+t-1;
while(a<=b)
{
x=i;y=i+t-1;
while(x<=y)
{
if(map[x][a]!=map[y][a])break;
x++;y--;
}
if(x<=y)break;
a++;
}
if(a<=b){f=0;continue;}
else {f=1;break;}
}
if(f==1)break;
}
if(f==1)return 1;
return 0;
}
int main()
{
int T;
int i,j;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
scanf("%d",&map[i][j]);
}
i=min(n,m);
for(;i>=1;i--)
{
if(fun(i))
{
printf("%d\n",i);
break;
}
}
}
return 0;
}