摘要:
1 /* 2 * kmp 3 */ 4 5 #include <cstdio> 6 #include <iostream> 7 8 using namespace std; 9 10 const int N = 1005;11 12 int next[N];13 char str[N], pat[N];14 15 void indexNext() {16 int k = 0;17 next[1] = 0;18 for (int i=2; pat[i]; ++i) {19 while (k && pat[k+1]!=pat[i]) k = next... 阅读全文
posted @ 2012-05-06 21:52
Try86
阅读(160)
评论(0)
推荐(0)
摘要:
1 /* 2 * kmp 3 * 利用next[]数组的性质求周期 4 */ 5 #include <stdio.h> 6 #include <string.h> 7 #define N 1000005 8 9 int next[N];10 char str[N];11 12 void indexNext() {13 int i, k = 0;14 next[1] = 0;15 for (i=2; str[i]; ++i) {16 while (k && str[k+1]!=str[i]) k = next[k];17 if (... 阅读全文
posted @ 2012-05-06 21:40
Try86
阅读(161)
评论(0)
推荐(0)
摘要:
1 /* 2 * kmp 3 */ 4 #include <cstdio> 5 #include <iostream> 6 7 using namespace std; 8 9 const int N = 10005;10 const int M = 1000005;11 12 int str[M], pat[N], next[N];13 14 void indexNext(int lenPat) {15 int k = 0;16 next[1] = 0;17 for (int i=2; i<=lenPat; ++i) {18 while (k &... 阅读全文
posted @ 2012-05-06 21:16
Try86
阅读(153)
评论(0)
推荐(0)
摘要:
1 /* 2 * kmp 3 */ 4 5 #include <cstdio> 6 #include <cstring> 7 #include <iostream> 8 9 using namespace std;10 11 const int N = 100005;12 13 char str[N<<1];14 char pat[N];15 int next[N];16 17 void indexNext() {18 int k = 0;19 next[1] = 0;20 for (int i=2; pat[i]; ++i) {21 while 阅读全文
posted @ 2012-05-06 20:28
Try86
阅读(195)
评论(0)
推荐(0)