摘要:
1 /* 2 * 字典树 3 */ 4 #include <cstdio> 5 #include <cstdlib> 6 #include <cstring> 7 #include <iostream> 8 9 using namespace std;10 11 const int N = 11;12 13 char str[N];14 struct node {//节点数据 15 int c; //统计前缀个数 16 node *child[26];17 node() {//初始化 18 c = 1;19 for (int i... 阅读全文
posted @ 2012-05-07 21:52
Try86
阅读(123)
评论(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 next[N];13 char pat[N], str[M];14 15 void indexNext() {16 int k = 0;17 next[1] = 0;18 for (int i=2; pat[i]; ++i) {19 while (k && pat... 阅读全文
posted @ 2012-05-07 17:41
Try86
阅读(184)
评论(0)
推荐(0)
摘要:
摘自:http://www.cnblogs.com/wuyiqi/archive/2012/01/05/2313746.html题意:求给定字符串含前缀的数量abab前缀为aababaabababab中共有六个子串是前缀a a ab ab aba abab所以答案为6利用kmp中的匹配原理可以完美的解决此题a---------d----- -----a---------d i j如上所示,假设两串字符完全相等,next[j]=i,代表s[1...i]==sum[j-i+1....j],这一段其实就是前缀i~j之间已经不可能有以j结尾的子串是前缀了,不然next【j】就不是 i 了设dp【i】: 阅读全文
posted @ 2012-05-07 12:56
Try86
阅读(1006)
评论(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 int next[N];14 char pat[N];15 16 void indexNext() {17 int k = 0;18 next[1] = 0;19 for (int i=2; pat[i]; ++i) {20 while (k && pat[k+1]! 阅读全文
posted @ 2012-05-07 07:12
Try86
阅读(193)
评论(0)
推荐(0)
摘要:
1 /* 2 * KMP 3 * 思路:把两个串连接,然后求next[]数组值 4 * 注意:当两个串都是重复串且重复子串一样是,要特殊处理 5 */ 6 7 #include <cstdio> 8 #include <iostream> 9 10 using namespace std;11 12 const int N = 50005;13 14 int next[N<<1];15 char str[N<<1], pat[N];16 17 void indexNext() {18 int k = 0;19 next[1] = 0;20 ... 阅读全文
posted @ 2012-05-07 07:01
Try86
阅读(278)
评论(0)
推荐(0)
浙公网安备 33010602011771号