当前位置:网站首页>Informatics Olympiad 1337: [example 3-2] word search tree | Luogu p5755 [noi2000] word search tree
Informatics Olympiad 1337: [example 3-2] word search tree | Luogu p5755 [noi2000] word search tree
2022-07-05 20:17:00 【Jun Yi_ noip】
【 Topic link 】
ybt 1337:【 example 3-2】 Word search tree
Luogu P5755 [NOI2000] Word search tree
【 Topic test site 】
1. Dictionary tree
【 Their thinking 】
solution 1: Dictionary tree
Dictionary tree template questions . Learn about dictionary tree in csdn search “ Dictionary tree ” or “tire Trees ”.
This question says that the total length of the document does not exceed 32K, 32 K B = 32 ∗ 1024 B = 32768 B 32KB = 32*1024B = 32768B 32KB=32∗1024B=32768B, The total number of characters will not exceed 33000 individual . Therefore, the total number of node pools is set to 33000.
【 Solution code 】
solution 1: Dictionary tree
#include<bits/stdc++.h>
using namespace std;
struct Node
{
int child[26];//child[i]: Character is a i+'A' The address of the child node
};
Node node[33000];
int p, root;// Root node root The address is 0, From address 1 Start assigning nodes
void insert(string s)// Insert words into the dictionary tree s
{
int pf = root;// The address of the currently concerned node
for(int i = 0; i < s.length(); ++i)
{
if(node[pf].child[s[i]-'A'] == 0)
node[pf].child[s[i]-'A'] = ++p;// Assign new nodes
pf = node[pf].child[s[i]-'A'];//pf Point to the next node
}
}
int getNodeNum(int r)// Get the root node address as r Node number of the tree of
{
int sum = 1;// I am 1 Nodes
for(int i = 0; i < 26; ++i)// Statistics r Number of subtree nodes
{
if(node[r].child[i] > 0)
sum += getNodeNum(node[r].child[i]);
}
return sum;
}
int main()
{
string s;
while(cin >> s)
insert(s);// Put the word s Insert dictionary tree
cout << getNodeNum(root);// Get the node number of the whole tree
return 0;
}
边栏推荐
- [quick start of Digital IC Verification] 6. Quick start of questasim (taking the design and verification of full adder as an example)
- 【数字IC验证快速入门】1、浅谈数字IC验证,了解专栏内容,明确学习目标
- Leetcode brush question: binary tree 14 (sum of left leaves)
- Practical demonstration: how can the production research team efficiently build the requirements workflow?
- Bzoj 3747 poi2015 kinoman segment tree
- leetcode刷题:二叉树12(二叉树的所有路径)
- Cocos2d-x项目总结中的一些遇到的问题
- July 4, 2022 - July 10, 2022 (UE4 video tutorial MySQL)
- CVPR 2022 | 常见3D损坏和数据增强
- Securerandom things | true and false random numbers
猜你喜欢
Oracle-表空间管理
leetcode刷题:二叉树18(最大二叉树)
[quick start to digital IC Verification] 8. Typical circuits in digital ICs and their corresponding Verilog description methods
Go language | 02 for loop and the use of common functions
leetcode刷题:二叉树14(左叶子之和)
【数字IC验证快速入门】3、数字IC设计全流程介绍
leetcode刷题:二叉树12(二叉树的所有路径)
B站UP搭建世界首个纯红石神经网络、基于深度学习动作识别的色情检测、陈天奇《机器学编译MLC》课程进展、AI前沿论文 | ShowMeAI资讯日报 #07.05
【数字IC验证快速入门】6、Questasim 快速上手使用(以全加器设计与验证为例)
Leetcode brush questions: binary tree 18 (largest binary tree)
随机推荐
Go language learning tutorial (XV)
Scala基础【HelloWorld代码解析,变量和标识符】
Parler de threadlocal insecurerandom
Leetcode: binary tree 15 (find the value in the lower left corner of the tree)
怎么挑选好的外盘平台,安全正规的?
Leetcode skimming: binary tree 17 (construct binary tree from middle order and post order traversal sequence)
Guidelines for application of Shenzhen green and low carbon industry support plan in 2023
Database logic processing function
c語言oj得pe,ACM入門之OJ~
强化学习-学习笔记4 | Actor-Critic
E. Singhal and Numbers(质因数分解)
Summer Challenge harmonyos - realize message notification function
SecureRandom那些事|真伪随机数
Leetcode(347)——前 K 个高频元素
Leetcode(695)——岛屿的最大面积
DP: tree DP
Bzoj 3747 poi2015 kinoman segment tree
About the priority of Bram IP reset
Based on vs2017 and cmake GUI configuration, zxing and opencv are used in win10 x64 environment, and simple detection of data matrix code is realized
Debezium series: PostgreSQL loads the correct last submission LSN from the offset