摘要:
找前缀个数。主要是理解trie树的含义吧,统计一个节点出现的次数就可以了。 1 #include<stdio.h> 2 #include<malloc.h> 3 #include<string.h> 4 #define MAXNUM 26 5 typedef struct tnode 6 { 7 int mark,count; 8 tnode *next[MAXNUM]; 9 10 }tnode;11 tnode *root;12 void init()13 {14 int i;15 root=(tnode*)malloc(sizeof(tnode)... 阅读全文
posted @ 2013-04-17 21:29
Yuki_i
阅读(152)
评论(0)
推荐(0)
摘要:
---恢复内容开始--- trie树,我是设置了号码结束标志,在insert函数里做处理:如果在插入的过程中,一直没有开辟新的节点,说明新插入的这个号码是某个已经插入了的号码的前缀,输出“NO”。如果在插入的过程中,经过了结束标志,说明这个新插入的号码之前已经插入了前缀号码,同样的,输出“NO”。此外,都输出“YES”。 1 #include<stdio.h> 2 #include<malloc.h> 3 #include<string.h> 4 typedef struct tnode 5 { 6 int mark; 7 tnode *next[10]; 阅读全文
posted @ 2013-04-17 21:23
Yuki_i
阅读(171)
评论(0)
推荐(0)
摘要:
做这道题的时候,我对KMP也是没有什么概念。。然后学长说,利用next数组就可以。思考了一下,觉得next数组大概是个这么回事:next数组是在第i个字符“失配”的情况下,跳转到next[i]所指向的第j个字符,再进行匹配。这样来看,既然可以跳转,那就说明i前面的字符一直到j后面一个字符这k个字符与j前面的k个字符就是一模一样的!如果不是这样,那么i失配的情况下,就不可以跳到j字符。 #include<stdio.h>#include<string.h>char s1[100005],s2[50005];int next[100005];void get_next(ch 阅读全文
posted @ 2013-04-17 19:31
Yuki_i
阅读(166)
评论(0)
推荐(0)
摘要:
#include<stdio.h>#include<string.h>long s[1000005],t[10005];int next[10005],m,n;void get_next(long t[10005]){ int i=0,j=-1;next[0]=-1; while(i<n) { if(j==-1||t[i]==t[j]) {++i; ++j; next[i]=j; } else j=next[j]; }}int index_kmp(long s[1000005],long... 阅读全文
posted @ 2013-04-17 19:00
Yuki_i
阅读(142)
评论(0)
推荐(0)
摘要:
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2087就是给你一个串和一个模式串,问,这个串中有多少个模式串。就是KMP啦,稍微修改一下就是匹配成功后返回匹配成功后的最后一个字符的位置的后一位,而不是第一位。因为是剪纸啦,不能剪过的再剪一次是吧。。 1 #include<stdio.h> 2 #include<string.h> 3 int next[1005]; 4 void get_next(char t[1005]) 5 { 6 int i=0,j=-1,len; 7 next[0]=-1; 8 len=strlen 阅读全文
posted @ 2013-04-17 18:48
Yuki_i
阅读(263)
评论(0)
推荐(0)

浙公网安备 33010602011771号