随笔分类 -  匹配

hdu 2896(AC自动机)
摘要:1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <iostream> 5 6 using namespace std; 7 8 const int N = 205; 9 const int L = 10005; 10 const int M = 100010; 11 12 int ans[5]; 13 char pat[N], str[L]; 14 struct node { 15 int n; 16 node *prefix; 17 node *. 阅读全文
posted @ 2012-05-12 20:20 Try86 阅读(325) 评论(1) 推荐(0)
hdu 2222(AC自动机)
摘要:参考:http://www.cppblog.com/mythit/archive/2009/04/21/80633.html 1 /* 2 * AC自动机 3 */ 4 #include <cstdio> 5 #include <cstdlib> 6 #include <cstring> 7 #include <iostream> 8 9 using namespace std;10 11 const int N = 51;12 const int L = 500001;13 const int M = 1000001;14 15 char pa 阅读全文
posted @ 2012-05-09 13:03 Try86 阅读(190) 评论(0) 推荐(0)
hdu 1671(字典树)
摘要:1 /* 2 * 字典树 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <cstdlib> 7 #include <iostream> 8 9 using namespace std;10 11 const int N = 11;12 13 bool yes;14 char str[N];15 struct node {16 bool flag;17 node *child[10];18 node() {19 flag = false;20 for (int i=... 阅读全文
posted @ 2012-05-08 07:11 Try86 阅读(141) 评论(0) 推荐(0)
hdu 1247(字典树)
摘要:1 /* 2 * 字典树 3 * 思路:把所有单词建成一棵字典树,然后把每个分成两部分,判断这两部分是否在树中 4 * 是,就符合条件。 5 */ 6 7 #include <cstdio> 8 #include <cstdlib> 9 #include <cstring>10 #include <iostream>11 12 using namespace std;13 14 const int N = 16;15 const int M = 50005;16 17 char strL[N], strR[N], dic[M][N]; 18 st 阅读全文
posted @ 2012-05-08 07:03 Try86 阅读(739) 评论(0) 推荐(0)
hdu 1251(字典树)
摘要: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 阅读(124) 评论(0) 推荐(0)
hdu 1686(kmp)
摘要: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 阅读(185) 评论(0) 推荐(0)
hdu 3336(kmp+dp)
摘要:摘自: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 阅读(1013) 评论(0) 推荐(0)
hdu 3746(kmp)
摘要: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)
hdu 2594(kmp)
摘要: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 阅读(282) 评论(0) 推荐(0)
hdu 2087(kmp)
摘要: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 阅读(163) 评论(0) 推荐(0)
hdu 1358(kmp)
摘要: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 阅读(163) 评论(0) 推荐(0)
hdu 1711(kmp)
摘要: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 阅读(154) 评论(0) 推荐(0)
hdu 2203(kmp)
摘要: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 阅读(197) 评论(0) 推荐(0)