
字典树
csu_xiji
这个作者很懒,什么都没留下…
展开
-
力扣 211. 添加与搜索单词 - 数据结构设计 字典树
https://leetcode-cn.com/problems/design-add-and-search-words-data-structure/思路:字典树经典题目。看数据范围,暴力比对的话大概率会超时。字典树就是前缀树,支持插入字符串、快速检索字符串 or 前缀是否出现过,当然它还有一些变体存在,比如01字典树等。详见我的这篇博客,此处就不多说了。字符 “.” 其实也挺好处理的,写个深搜嘛。class TireNode{public: array<TireNode*, 26&原创 2021-10-20 00:15:37 · 246 阅读 · 1 评论 -
力扣 1707. 与数组中元素的最大异或值 01字典树 贪心
https://leetcode-cn.com/problems/maximum-xor-with-an-element-from-array/思路:01字典树,只不过多了一个最大值限制。那么在字典树的每个节点中记录一下到当前位置的最小值,如果该最小值满足限制,那么就可以走到该节点,否则不行。class Tire{public: vector<Tire*> child; int min_value; Tire():min_value(0x3f3f3f3f)原创 2021-06-06 21:22:57 · 155 阅读 · 0 评论 -
力扣 421. 数组中两个数的最大异或值 01字典树 贪心
https://leetcode-cn.com/problems/maximum-xor-of-two-numbers-in-an-array/思路:01字典树模板题……贪心就比较好想了,根据二进制的性质,显然要从高位枚举。class Tire{public: Tire() { root.resize(2,nullptr); } void insert(int num) { int val=1<<30;原创 2021-05-16 02:32:48 · 183 阅读 · 0 评论 -
力扣 208. 实现 Trie (前缀树) 字典树
https://leetcode-cn.com/problems/implement-trie-prefix-tree/思路:每个节点存储26个子节点——相当于从小写字母aaa到zzz,我们还需要知道当前节点是否是某个字符串的尾端,由于本题不需要计数,那么用一个boolboolbool值记录即可。class Trie {public: /** Initialize your data structure here. */ Trie() { child.resize(2原创 2021-04-14 17:39:54 · 746 阅读 · 0 评论 -
Round A 2020 - Kick Start 2020 Bundling 字典树+贪心
https://codingcompetitions.withgoogle.com/kickstart/round/000000000019ffc7/00000000001d3ff3题目大意:每组数据给nnn个字符串,每个字符串仅能划分到某一个组里面,且这个组的价值就等于该组所有字符串的最长公共前缀的长度。现在给一个数kkk,让你给这些字符串划分组,使得所有刚好含有kkk个字符串的组的价值之和最...原创 2020-03-22 17:16:55 · 678 阅读 · 0 评论 -
Light OJ 1269 字典树
http://lightoj.com/volume_showproblem.php?problem=1269Little 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 al...原创 2019-03-23 16:53:36 · 259 阅读 · 0 评论 -
Light OJ 1224 字典树
http://lightoj.com/volume_showproblem.php?problem=1224Given 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 i...原创 2019-03-23 15:28:09 · 202 阅读 · 0 评论 -
POJ 3630 字典树
http://poj.org/problem?id=3630DescriptionGiven a list of phone numbers, determine if it is consistent in the sense that no number is the prefix of another. Let's say the phone catalogue listed the...原创 2019-03-23 15:05:35 · 198 阅读 · 0 评论 -
POJ 2001 字典树
http://poj.org/problem?id=2001DescriptionA prefix of a string is a substring starting at the beginning of the given string. The prefixes of "carbon" are: "c", "ca", "car", "carb", "carbo", and "ca...原创 2019-03-23 14:44:17 · 347 阅读 · 0 评论 -
HDU 2072 字典树
http://acm.hdu.edu.cn/showproblem.php?pid=2072Problem Descriptionlily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词的总数。下面你的任务是帮助xiaoou333解决这个问题。Input有多组数据,每组一行,每组就是一篇小文章。每篇小文章都是由小写字母...原创 2019-03-23 00:16:17 · 392 阅读 · 0 评论 -
HDU 1251 字典树
http://acm.hdu.edu.cn/showproblem.php?pid=1251Problem DescriptionIgnatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己的前缀).Input输入数据的第一部分是一张单词表,每行一个单词,单词的长...原创 2019-03-22 23:37:26 · 150 阅读 · 0 评论 -
HDU 4825 01字典树
http://acm.hdu.edu.cn/showproblem.php?pid=4825Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包含了N个正整数,随后 Prometheus 将向 Zeus 发起M次询问,每次询问中包含一个正整数 S ,之后 Zeus 需要在集合当中找出一个正整数 K ,使得 K 与 S 的异或结果最大。Prom...原创 2019-03-22 22:45:45 · 139 阅读 · 0 评论 -
字典树
什么是字典树:字典树又称单词查找树,Trie树,是一种树形结构,是一种哈希树的变种。典型应用是用于统计,排序和保存大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计。它的优点是:利用字符串的公共前缀来减少查询时间,最大限度地减少无谓的字符串比较,查询效率比哈希树高。字典树有什么性质:根节点不包含字符,除根节点外每一个节点都只包含一个字符; 从根节点到某一节点,路...原创 2019-03-22 22:20:37 · 272 阅读 · 0 评论