标签:style blog http color io os java ar for
2 5 ABABA ABABA
2
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 int row,col,fail[10100],x,y; 18 char str[10010][80]; 19 bool cmp(int a,int b){ 20 for(int i = 0; i < row; i++) 21 if(str[i][a] != str[i][b]) return false; 22 return true; 23 } 24 int main() { 25 while(~scanf("%d %d",&row,&col)){ 26 for(int i = 0; i < row; i++) 27 scanf("%s",str[i]); 28 fail[0] = fail[1] = 0; 29 for(int i = 1; i < row; i++){ 30 int j = fail[i]; 31 while(j && strcmp(str[i],str[j])) j = fail[j]; 32 if(!strcmp(str[i],str[j])) fail[i+1] = j+1; 33 else fail[i+1] = 0; 34 } 35 x = row - fail[row]; 36 fail[0] = fail[1] = 0; 37 for(int i = 1; i < col; i++){ 38 int j = fail[i]; 39 while(j && !cmp(i,j)) j = fail[j]; 40 if(cmp(i,j)) fail[i+1] = j+1; 41 else fail[i+1] = 0; 42 } 43 y = col - fail[col]; 44 printf("%d\n",x*y); 45 } 46 return 0; 47 }
标签:style blog http color io os java ar for
原文地址:http://www.cnblogs.com/crackpotisback/p/3980210.html