模板,但是对这个算法还是不太清楚,真实不明觉厉....
1 #include <iostream> 2 #include <cstdio> 3 #include <string.h> 4 #pragma warning ( disable : 4996 ) 5 using namespace std; 6 7 inline int Max(int a,int b) { return a>b?a:b; } 8 inline int Min(int a,int b) { return a>b?b:a; } 9 const int inf = 0x3f3f3f3f; 10 const int maxn = 1e5+1e4+5; 11 12 char str[maxn]; 13 char nstr[maxn<<1]; 14 int maxlen[maxn<<1]; 15 int len, plen, ans; 16 17 void init() 18 { 19 memset( nstr, 0, sizeof(nstr) ); 20 memset( maxlen, 0, sizeof(maxlen) ); 21 len = strlen(str); 22 nstr[0] = '$'; nstr[1] = '#'; 23 24 int j = 2; 25 for ( int i = 0; i < len; i++ ) 26 { 27 nstr[j++] = str[i]; 28 nstr[j++] = '#'; 29 } 30 nstr[j] = '