Trie
穷源溯流
路很长,尽管走便是。
展开
-
UVa10887 Concatenation of Languages(Trie)
Sample Input23 2catdogmouseratbat1 1abccabSample OutputCase 1: 6Case 2: 1有 n 个 A 串,m 个 B 串,问可以组成多少种 AB 串将所有的组合放入字典树中即可,话说为什么会有空串啊喂const int N=2e6+5; int n,m; int i,j,k; int t[N][26],tot=0; int vis[N]; cha...原创 2021-02-24 18:01:04 · 162 阅读 · 0 评论 -
LightOJ 1269 Consecutive Sum(Trie+贪心)
Little Jimmy is learning how to add integers. As in decimal the digits are 0 to 9, it makes a bit hard for him to understand the summation of all pair of digits. Since addition of numbers requires the knowledge of adding digits. So, his mother gave him a s原创 2021-02-24 17:22:05 · 176 阅读 · 0 评论 -
HDU 1247 Hat’s Words(Trie)
给出多个单词组成单词表,问这些单词中有哪些可以拆成两个单词,并按字典序输出按字典序输出自然要借助 set,对于每一个单词,我们将其正序放入字典树,再将其逆序放入字典树,这样存在两颗字典树对于每一个单词将进行询问,如果可以由两个单词表示,那么一定存在位置x,使得 1~x 为一个单词,x+1~len 为一个单词,只要找是否存在这样的x 即可const int N=5e4+5; int n,m; int i,j,k; int t[N*50][26][2]...原创 2021-02-23 14:50:36 · 140 阅读 · 0 评论 -
POJ 1816 Wild Words(Trie+DFS)
题目比较毒瘤给出 n 个模式串,m 个单词,查询每一个单词与哪一个模式串匹配,其中 ?可以表示任意一个单词,* 可以表示为 空或者任意多个单词一看到这个题不应该向 AC 自动机考虑吗?发现题目中单词的数目不多,且单词的长度很小,故在查询的时候采用暴力的方式,先利用模式串建好字典树在查询过程中利用 dfs 的方式,但是要注意的是遇到 * 之后,由于其可以为空,所以单词的长度可以不再增加,当然也可以表示剩余的所有字母但是这样还是不对,在 dfs 过程中不可以 return:...原创 2021-02-19 16:02:12 · 174 阅读 · 0 评论 -
POJ 2408 Anagram Groups(Trie+思维)
给出多个单词,每个单词的长度没说(差评),每个单词只要所有的字母相同可以认为是同一个单词,将所有的同一个单词放入集合中,输出前 5 个集合数量最大的集合注意:若一个集合中只有一个单词 word,不能说明 word 只出现过一次题目不难,但是处理起来有几个坑点题目可以用 map+set 过,但是常数较大,我们采用字典树,将每一个单词在树上的标记作为桶 将不同的字符串转化为字典序最小的,可以采用快排,这里采用基数排序 可能是 set 里面有 const 修饰的形参,所以 cmp 函数...原创 2021-02-16 16:43:55 · 336 阅读 · 0 评论 -
POJ 1451 T9(Trie+思维)
DescriptionBackgroundA while ago it was quite cumbersome to create a message for the Short Message Service (SMS) on a mobile phone. This was because you only have nine keys and the alphabet has more than nine letters, so most characters could only be en原创 2021-02-15 14:36:52 · 227 阅读 · 0 评论 -
LightOJ DNA Prefix(Trie)
Given a set ofnDNA samples, where each sample is a string containing characters from{A, C, G, T}, we are trying to find a subset of samples in the set, where the length of the longest common prefix multiplied by the number of samples in that subset is m...原创 2021-02-15 12:31:06 · 194 阅读 · 0 评论 -
POJ 3630 Phone List(Trie)
有 t 组测试,每组测试有 n 个 01 字符串,查询每个字符串是否是其他字符串的前缀题目利用字典树应该是可以在插入过程中得出答案const int N=1e5+5; int n,m; int i,j,k; char s[N][15]; int t[N][10]; int sum[N],tot=0;int idx(char ch){ return ch-'0'; }void insert(char *s,int rt){ ...原创 2021-02-15 10:48:51 · 158 阅读 · 0 评论 -
POJ 2001 Shortest Prefixes(Trie)
给出多组字符串,求每一个字符串可以唯一表示的前缀利用字典树,对于每一个前缀标记出现的次数,遇到前缀出现次数为 1 时返回const int N=2e4+5; int n,m; int i,j,k; char s[N][25]; int t[N][26]; int sum[N],tot=0;int idx(char ch){ return ch-'a'; }void insert(char *s,int rt){ for(...原创 2021-02-15 10:13:28 · 153 阅读 · 0 评论 -
HDU 2072 单词数(Trie)
注意审题,有多组测试样例,每组一行#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <sstream>#define rush() int T;cin>>T;while(T--)#define ms(a,b) memset(a,b,sizeof a)#define lowb...原创 2021-02-07 15:21:37 · 226 阅读 · 0 评论 -
HDU 1251 统计难题(Trie)
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#define rush() int T;cin>>T;while(T--)#define ms(a,b) memset(a,b,sizeof a)#define lowbit(x) ((x)&(-x))#define inf (1e1...原创 2021-02-07 14:52:58 · 280 阅读 · 1 评论 -
洛谷 P5149 会议座位(树状数组+Trie)
题目是一道求逆序对的题目,但是我们先要将每一个名字转化为数字再进行计算求逆序对的个数用树状数组或归并即可题目有个坑点,名字包含大小写字母,所以字典树需要开大一点#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#define ss(a) scanf("%s",a)#define sd(a) scanf("...原创 2021-02-04 23:32:19 · 217 阅读 · 0 评论 -
洛谷 P2580 于是他错误的点名开始了(Trie)
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#define ss(a) scanf("%s",a)#define sd(a) scanf("%d",&a)#define pd(a) printf("%d\n",a)#define rush() int T;cin>>T;w...原创 2021-02-04 22:45:55 · 254 阅读 · 0 评论