题目链接:http://hihocoder.com/problemset/problem/1014 ,刚学的字典树,就当模板了。
最近都没有好好刷题,罪过罪过。
#include <iostream> #include <cstdio> #include <vector> #include <queue> #include <stack> #include <cmath> #include <string> #include <string.h> #include <algorithm> using namespace std; #define LL long long const int maxn = 1000000; struct Trie { int ch[maxn][26]; int cnt[maxn]; int size; Trie() { size = 1; memset(ch[0] , 0 , sizeof(ch[0])); memset(cnt , 0 , sizeof(cnt)); } int index(char c) { return c - 'a'; } void insert(char *s , int v) { int i , u; for(i = u = 0 ; s[i] != '