九野的博客,转载请注明出处:http://blog.csdn.net/acmmmm/article/details/12250267
注意字典树的节点应该为 : 单词个数*单词长度
注意Trie结构体函数中的idx
字典树模版:
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
#define ll int
#define Word_Len 50500
#define Sigma_size 95
struct Trie{
ll ch[Word_Len][Sigma_size], sz; //Word_Len是字典树的节点数 若都是小写字母Sigma_size=26 sz为当前节点数
ll Have_word[Word_Len]; //这个节点下有几个单词
ll val[Word_Len]; // 这个节点附带的信息,初始化为0表示这个节点不存在单词,所以节点带的信息必须!=0
ll pre[Word_Len];
char he[Word_Len];
ll Newnode(){memset(ch[sz], 0, sizeof(ch[sz])); val[sz]=Have_word[sz]=0; return sz++;}
void init() //初始化字典树
{ sz = 0; Newnode();}//初始化
ll idx(char c){return c-32