字典树

HDU 3460 Ancient Printer(字典树)

淺唱寂寞╮ 提交于 2020-01-14 05:52:49
Ancient Printer Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) Total Submission(s) : 1 Accepted Submission(s) : 1 Problem Description The contest is beginning! While preparing the contest, iSea wanted to print the teams’ names separately on a single paper. Unfortunately, what iSea could find was only an ancient printer: so ancient that you can’t believe it, it only had three kinds of operations: ● ‘a’-‘z’: twenty-six letters you can type ● ‘Del’: delete the last letter if it exists ● ‘Print’: print the word you have typed in the printer The printer was empty in

D. Dr. Evil Underscores---字典树+dp/贪心

吃可爱长大的小学妹 提交于 2020-01-13 14:44:35
第二天叫醒我的不是闹钟,是梦想! Today, as a friendship gift, Bakry gave Badawy n integers a1,a2,…,an and challenged him to choose an integer X such that the value max1≤i≤n(ai⊕X) is minimum possible, where ⊕ denotes the bitwise XOR operation. As always, Badawy is too lazy, so you decided to help him and find the minimum possible value of max1≤i≤n(ai⊕X). Input The first line contains integer n (1≤n≤105). The second line contains n integers a1,a2,…,an (0≤ai≤230−1). Output Print one integer — the minimum possible value of max1≤i≤n(ai⊕X). Examples inputCopy 3 1 2 3 outputCopy 2 inputCopy 2 1 5 outputCopy 4 Note

字典树(Trie树)实现与应用

余生长醉 提交于 2020-01-10 18:21:47
一、概述   1、基本概念   字典树,又称为单词查找树,Tire数,是一种树形结构,它是一种哈希树的变种。      2、基本性质 根节点不包含字符,除根节点外的每一个子节点都包含一个字符 从根节点到某一节点。路径上经过的字符连接起来,就是该节点对应的字符串 每个节点的所有子节点包含的字符都不相同   3、应用场景   典型应用是用于统计,排序和保存大量的字符串(不仅限于字符串),经常被搜索引擎系统用于文本词频统计。   4、优点   利用字符串的公共前缀来减少查询时间,最大限度的减少无谓的字符串比较,查询效率比哈希树高。 二、构建过程   1、字典树节点定义 class TrieNode // 字典树节点 { private int num;// 有多少单词通过这个节点,即由根至该节点组成的字符串模式出现的次数 private TrieNode[] son;// 所有的儿子节点 private boolean isEnd;// 是不是最后一个节点 private char val;// 节点的值 TrieNode() { num = 1; son = new TrieNode[SIZE]; isEnd = false; } }   2、字典树构造函数 Trie() // 初始化字典树 { root = new TrieNode(); }   3、建立字典树 // 建立字典树

字典树(Trie Tree)

有些话、适合烂在心里 提交于 2020-01-10 07:32:10
基本概念和性质 在计算机科学中,trie,又称前缀树或字典树或单词搜索树,是一种有序树,用于保存关联数组,其中的键通常是字符串。与二叉查找树不同,键不是直接保存在节点中,而是由节点在树中的位置决定。一个节点的所有子孙都有相同的前缀,也就是这个节点对应的字符串,而根节点对应空字符串。一般情况下,不是所有的节点都有对应的值,只有叶子节点和部分内部节点所对应的键才有相关的值。 本文地址: http://www.cnblogs.com/archimedes/p/trie-tree.html ,转载请注明源地址。 在图示中,键标注在节点中,值标注在节点之下。每一个完整的英文单词对应一个特定的整数。Trie 可以看作是一个确定有限状态自动机,尽管边上的符号一般是隐含在分支的顺序中的。 键不需要被显式地保存在节点中。图示中标注出完整的单词,只是为了演示 trie 的原理。 trie 中的键通常是字符串,但也可以是其它的结构。 trie 的算法可以很容易地修改为处理其它结构的有序序列,比如一串数字或者形状的排列。比如,bitwise trie 中的键是一串位元,可以用于表示整数或者内存地址。 Trie树是一种树形结构,是一种哈希树的变种。 典型应用是用于统计和排序大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计。它的优点是:最大限度地减少无谓的字符串比较,查询效率比哈希表高

hdu 5536 Chip Factory 字典树+bitset 铜牌题

China☆狼群 提交于 2020-01-10 05:09:06
Chip Factory Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 1842 Accepted Submission(s): 833 Problem Description John is a manager of a CPU chip factory, the factory produces lots of chips everyday. To manage large amounts of products, every processor has a serial number. More specifically, the factory produces chips today, the -th chip produced this day has a serial number . At the end of the day, he packages all the chips produced this day, and send it to wholesalers. More specially, he writes a checksum number on the package, this

Intelligent IME HDU - 4287 字典树

自闭症网瘾萝莉.ら 提交于 2020-01-10 03:22:49
题意: 给你m个字符串,每一个字符对应一个数字,如下: 2 : a, b, c 3 : d, e, f 4 : g, h, i 5 : j, k, l 6 : m, n, o 7 : p, q, r, s 8 : t, u, v 9 : w, x, y, z 输入n个数字串,问这个数字串可以对应几个字符串 比如ade这个字符串对应的数字串就是233 题解: 用这m个字符串建立一颗字典树,对于每一个节点维护一个变量val,他就代表(从树根到这个节点这一个数字串)有多少个对应的字符串 每次插入的时候记录一下最大值就完了 代码: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <algorithm> 6 using namespace std; 7 typedef struct Trie* TrieNode; 8 char s[130]; 9 char v[5005][10]; 10 struct Trie 11 { 12 int val; 13 TrieNode next[8]; 14 Trie() 15 { 16 val = 0; 17 memset(next,NULL,sizeof(next)); 18 } 19 }; 20 21 void

HDU 5536 Chip Factory 字典树

假如想象 提交于 2020-01-09 23:58:02
Chip Factory Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5536 Description John is a manager of a CPU chip factory, the factory produces lots of chips everyday. To manage large amounts of products, every processor has a serial number. More specifically, the factory produces n chips today, the i-th chip produced this day has a serial number si. At the end of the day, he packages all the chips produced this day, and send it to wholesalers. More specially, he writes a checksum number on the package, this checksum is defined as below: maxi,j,k(si+sj)⊕sk

Java字典树(Trie)数据结构

做~自己de王妃 提交于 2020-01-07 18:51:08
Java字典树(Trie)数据结构 数据结构计算机编程中的关键内容,了解什么时候使用以及为什么使用是非常重要的。本文介绍字典树(Trie,发音try)数据结构,理解其实现并分析其复杂度。 1. 字典树(Trie) 字典树不是很知名,一般课程中提及不多,但不代表其不重要。有时也称为基数树和前缀树(因为能根据前缀进行搜索),它是基于树的数据结构,节点存储的字符(通常为字符串中的字符),通过向下遍历树的分支路径可以获得单词或字符串。 节点在树中的位置定义了与该节点相关联的键,这与二叉搜索树不同,二叉搜索树中节点存储的键只对应于该节点。节点所有后代具有相同的前缀,根节点关联空字符串。 首先看TrieNode节点类的实现: import java.util.HashMap; import java.util.Map; class TrieNode { private final Map<Character, TrieNode> children = new HashMap<>(); private boolean endOfWord; Map<Character, TrieNode> getChildren() { return children; } boolean isEndOfWord() { return endOfWord; } void setEndOfWord(boolean

偏序+拓扑序+字典树

耗尽温柔 提交于 2020-01-01 01:38:37
题目描述 给定n个字符串,互不相等,你可以任意指定字符之间的大小关系(即重定义字典序),求有多少个串可能成为字典序最小的串,并输出它们 输入描述: 第一行一个数表示n之后n行每行一个字符串表示给定的字符串 输出描述: 第一行输出一个数x表示可行的字符串个数之后输出x行,每行输出一个可行的字符串输出的顺序和输入的顺序一致 示例1 输入 6 mcfx ak ioi wen l a 输出 5 mcfx ioi wen l a #include <bits/stdc++.h> #define INF 0x3f3f3f3f using namespace std; typedef struct node{ string s;int biao; friend bool operator <(node aa,node bb){ return aa.s.length()<bb.s.length(); } }node; string str[30005]; node dd[30005]; int cnt,root; typedef struct nop{ int a[26],ans; }nop; nop d[300005]; bool vvis[30005]; int newnode(){ cnt++;d[cnt].ans=0; for(int i=0;i<26;i++) d[cnt].a[i]=0

LA、Remember the Word (字典树, 简单dp)

霸气de小男生 提交于 2019-12-24 14:09:30
传送门 题意: 给你一个初始串 S,strlen(s) <= 3e5 然后给你 n 个单词。 n <= 4000, 每个单词的长度不超过 100 ;    问你这个初始串,分割成若干个单词的连接的方案;(这些单词必须是给定的n个单词中的任意一个,一个单词可以被使用多次。) 解: 将 n 个单词建个字典树;    dp[ i ] 表示,S的 0 ~ i - 1 切割成若干个 单词的方案数;    枚举S, 枚举到 当前位置 i; 然后就在字典树找,以 S 的 i + 1 开始的, 能不能找到一个单词与之匹配;    若能找到, 假设单词为 i + 1 ~ j; 那么就有 dp[ j + 1 ] = ( dp[ j + 1 ] + dp[ i ] ) % mod    这只是个简单dp; 和字典树的简单应用的结合。 #include <bits/stdc++.h> #define LL long long #define rep(i, j, k) for(int i = j; i <= k; i++) #define dep(i, j, k) for(int i = k; i >= j; i--) #define INF 0x3f3f3f3f #define inf 0x3f3f3f3f3f3f3f3f #define mem(i, j) memset(i, j, sizeof(i))