hdu 4618 Palindrome Sub-Array(暴力啊,3级)

Palindrome Sub-Array

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 249    Accepted Submission(s): 129

Problem Description
  A palindrome sequence is a sequence which is as same as its reversed order. For example, 1 2 3 2 1 is a palindrome sequence, but 1 2 3 2 2 is not. Given a 2-D array of N rows and M columns, your task is to find a maximum sub-array of P rows and P columns, of which each row and each column is a palindrome sequence.
 
Input
  The first line of input contains only one integer, T, the number of test cases. Following T blocks, each block describe one test case.   There is two integers N, M (1<=N, M<=300) separated by one white space in the first line of each block, representing the size of the 2-D array.   Then N lines follow, each line contains M integers separated by white spaces, representing the elements of the 2-D array. All the elements in the 2-D array will be larger than 0 and no more than 31415926.
 
Output
  For each test case, output P only, the size of the maximum sub-array that you need to find.
 
Sample Input
1 5 10 1 2 3 3 2 4 5 6 7 8 1 2 3 3 2 4 5 6 7 8 1 2 3 3 2 4 5 6 7 8 1 2 3 3 2 4 5 6 7 8 1 2 3 9 10 4 5 6 7 8
 
Sample Output
4
 
Source
 
Recommend
zhuyuanchen520

思路:直接暴力N^5,诸多的break优化就能过,多校最水的一题了,居然没敢敲,泪奔啊。

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #define FOR(ii,nn) for(int ii=1;ii<=nn;++ii)
 5 using namespace std;
 6 const int mm=309;
 7 int n,m,cas;
 8 int f[mm][mm];
 9 bool judge(int x,int y,int zk)
10 {
11   int a,b;
12   for(int i=x;i<x+zk;++i)
13   { a=y;b=y+zk-1;
14     while(a<b)
15     {
16       if(f[i][a++]!=f[i][b--])return 0;
17     }
18   }
19   for(int i=y;i<y+zk;++i)
20   {
21     a=x;b=x+zk-1;
22     while(a<b)
23     {
24       if(f[a++][i]!=f[b--][i])return 0;
25     }
26   }
27   return 1;
28 }
29 int main()
30 {
31   while(~scanf("%d",&cas))
32   {while(cas--)
33     {scanf("%d%d",&n,&m);
34     FOR(i,n)FOR(j,m)
35     scanf("%d",&f[i][j]);
36     int z,ans;ans=0;
37     FOR(i,n)FOR(j,m)
38     {
39       z=min(n-i,m-j)+1;
40       if(z<=ans)break;
41       for(int k=z;k>=1;--k)
42       if(judge(i,j,k))
43       { ans=max(ans,k);
44         break;
45       }
46     }
47      printf("%d\n",ans);
48     }
49   }
50   return 0;
51 }
View Code

 

 

posted @ 2013-07-26 13:21  剑不飞  阅读(290)  评论(0编辑  收藏  举报