我还是图样啊....比赛的时候没敢暴力去搜...
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cstring> 4 #include <map> 5 #include <ctime> 6 #include <cmath> 7 using namespace std; 8 #define LL __int64 9 char dp[301][301][301]; 10 int p[301][301]; 11 int n,m; 12 int dfs(int x,int y,int step) 13 { 14 int i,j,k; 15 if(step == 1) 16 return 1; 17 else if(step == 0) 18 return 1; 19 if(x > n||y > m) 20 return 2; 21 if(dp[x][y][step] == 1) 22 return 1; 23 else if(dp[x][y][step] == 2) 24 return 2; 25 int flag = 1; 26 for(i = x,j = x+step-1,k = 1;k <= step/2&&flag;i ++,j --,k ++) 27 { 28 if(p[i][y] == p[j][y]&&p[i][y] == p[i][y+step-1]) 29 ; 30 else 31 flag = 0; 32 } 33 for(i = y,j = y+step-1,k = 1;k <= step/2&&flag;i ++,j --,k ++) 34 { 35 if(p[x][i] == p[x][j]&&p[x][i] == p[x+step-1][i]) 36 ; 37 else 38 flag = 0; 39 } 40 if(flag == 0) 41 { 42 dp[x][y][step] = 2; 43 return 2; 44 } 45 else if(flag) 46 { 47 return dp[x+1][y+1][step-2] = dfs(x+1,y+1,step-2); 48 } 49 return 0; 50 } 51 int main() 52 { 53 int t,i,j,k,flag; 54 scanf("%d",&t); 55 while(t--) 56 { 57 scanf("%d%d",&n,&m); 58 memset(dp,0,sizeof(dp)); 59 for(i = 1;i <= n;i ++) 60 { 61 for(j = 1;j <= m;j ++) 62 { 63 scanf("%d",&p[i][j]); 64 } 65 } 66 flag = 1; 67 for(i = min(n,m);i >= 2&&flag;i --) 68 { 69 for(j = 1;j <= n-i+1&&flag;j ++) 70 { 71 for(k = 1;k <= m-i+1&&flag;k ++) 72 { 73 if(dfs(j,k,i) == 1) 74 flag = 0; 75 } 76 } 77 if(!flag) break; 78 } 79 printf("%d ",i); 80 } 81 return 0; 82 }