#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
const int maxn = 311;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
int a[maxn][maxn];
int n, m;
bool ok(int i, int j, int k) {
int h, l;
for (h = 0; h < k; ++h) {
for (l = 0; l <= k - l; ++l) {
if (a[i + h][j + l] != a[i + h][j + k - l - 1])
return false;
if (a[i + l][j + h] != a[i + k - l - 1][j + h])
return false;
}
}
return true;
}
bool go(int n, int m, int k) {
int i, j;
for (i = 0; i + k <= n; ++i)
for (j = 0; j + k <= m; ++j) {
if (ok(i, j, k))
return true;
}
return false;
}
int main() {
int i, j, k;
int T;
scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &m);
for (i = 0; i < n; ++i)
for (j = 0; j < m; ++j)
scanf("%d", a[i] + j);
int ans = 0;
for (k = min(n, m); k >= 1; --k) {
if (go(n, m, k)) {
ans = k;
break;
}
}
printf("%d\n", ans);
}
return 0;
}
HDU 4618
最新推荐文章于 2015-07-18 15:04:07 发布