标签:des style blog http color os strong io
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 6169 | Accepted: 2573 |
Description
Input
Output
Sample Input
2 5 ABABA ABABA
Sample Output
2
Hint
Source
1 #include<iostream> 2 #include<cstring> 3 #include<cstdlib> 4 #include<cstdio> 5 #include<algorithm> 6 using namespace std; 7 const int row =10050; 8 const int cow =80; 9 char str[row][cow]; 10 int next[row][cow]; 11 int RR,CC; 12 int main() 13 { 14 while(scanf("%d%d",&RR,&CC)!=EOF) 15 { 16 for(int i=0;i<RR;i++) 17 scanf("%s",str[i]); 18 int i,j,k; 19 //先求出每一行的next 20 int max_row=-1; 21 for(k=0;k<RR;k++) 22 { 23 i=0; j=-1; 24 next[k][0]=-1; 25 while(i<CC) 26 { 27 if(j==-1||str[k][i]==str[k][j]) 28 { 29 i++; 30 j++; 31 next[k][i]=j; 32 } 33 else j=next[k][j]; 34 } 35 if(max_row<(CC-next[k][CC])) 36 max_row=(CC-next[k][CC]); 37 } 38 int max_cow=-1; 39 //求出所有列中的最小循环节 40 for(k=0;k<CC;k++) 41 { 42 i=0; 43 j=-1; 44 next[0][k]=-1; 45 while(i<RR) 46 { 47 if(j==-1||str[i][k]==str[j][k]) 48 { 49 i++; 50 j++; 51 next[i][k]=j; 52 } 53 else 54 j=next[j][k]; 55 } 56 if(max_cow<(RR-next[RR][k])) 57 max_cow=(RR-next[RR][k]); 58 } 59 printf("%d\n",max_row*max_cow); 60 } 61 return 0; 62 }
POJ--2158--------------Milking Grid(最小覆盖字符矩阵)---(开二维kmp),布布扣,bubuko.com
POJ--2158--------------Milking Grid(最小覆盖字符矩阵)---(开二维kmp)
标签:des style blog http color os strong io
原文地址:http://www.cnblogs.com/gongxijun/p/3879868.html