hdu4287字典树
来源:互联网 发布:check point 数据库 编辑:程序博客网 时间:2024/06/06 15:36
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#include <queue>#include <string>#include <string.h>#include <map>#include <vector>const int nodeSize = 5001*6 ;const int alphaSize = 26 ;struct Trie{ int root ; int totel ; int next[nodeSize][alphaSize] ; int cnt[nodeSize] ; int newNode(){ memset(next[totel] , 0 , sizeof(next[totel])) ; cnt[totel] = 0 ; return totel++ ; } void clear(){ totel = 0 ; root = newNode() ; } void add(char *s){ int now = root ; for(int i = 0 ; s[i] ; i++){ int son = s[i] - 'a' ; if(! next[now][son]) next[now][son] = newNode() ; now = next[now][son] ; } cnt[now]++ ; }};Trie trie ;char dir[10][5] = {"" , "" , "abc" , "def" , "ghi" , "jkl" , "mno" , "pqrs" , "tuv" , "wxyz"} ;int query(char *s , int now){ if(*s == 0) return trie.cnt[now] ; int res = 0 ; int d = *s - '0' ; for(int i = 0 ; i < strlen(dir[d]) ; i++){ int son = dir[d][i] - 'a' ; if(! trie.next[now][son]) continue ; res += query(s+1 , trie.next[now][son]) ; } return res ;}int main(){ int t , n , m ; scanf("%d" , &t) ; while(t--){ scanf("%d%d" , &n , &m) ; for(int i = 0 ; i < n ; i++) scanf("%s" , ask[i]) ; trie.clear() ; while(m--){ scanf("%s" , word) ; trie.add(word) ; } for(int i = 0 ; i < n ; i++) printf("%d\n" , query(ask[i] , trie.root)) ; } return 0 ;}
0 0
- hdu4287(字典树)
- hdu4287(字典树)
- hdu4287字典树
- hdu4287 Intelligent IME-字典树
- hdu4287 Intelligent IME (字典树)
- hdu4287 Intelligent IME(字典树)
- HDU4287(线段树)
- 字母树hdu4287
- hdu4287
- hdu4287
- HDU4287
- HDU4287
- Trie树 hdu4287 Intelligent IME
- HDU4287 Intelligent IME(Trie树,map)
- hdu4287 水题
- 【STL】 hdu4287 Intelligent IME
- HDU4287:Intelligent IME
- HDU4287- Intelligent IME
- 多项式horner算法学习
- 负载均衡(一)基于接口、方法、参数的路由
- QT 常用快捷键
- android:layout_gravity和android:gravity的使用区别
- SQL_1.认识sql
- hdu4287字典树
- 深度学习系列(3.3)——神经网络结构
- java线程基础知识
- LeetCode bug记录
- ThinkPHP 笔记1 起步
- Android Studio下Android应用开发集成百度语音合成使用方法样例
- ZZULI 1869: Mathematics and Geometry【数学】
- D22
- pip install提示编码错误