BZOJ 2537 [neerc2007]Language Recognition Trie树 树Hash
来源:互联网 发布:算法时代pdf下载 编辑:程序博客网 时间:2024/06/09 19:55
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2537
题目大意:
求一个包含且仅包含给定
题解:
建立
代码:
#include <bits/stdc++.h>using namespace std;#define MAXN 5005typedef unsigned long long ll;int n;char buf[35];int len;struct Node{ int next[26]; int end; int &operator[](int x){return next[x];}}tr[MAXN*30];int tot;struct Hash{ ll val; int next;}hash[MAXN*30];const int MOD=(1<<15)-1;int head[MOD];int cnt;void Addhash(const ll &val){ int tmp=val&MOD; hash[++cnt].val=val; hash[cnt].next=head[tmp]; head[tmp]=cnt;}bool Query(const ll &val){ int tmp=val&MOD; for(int i=head[tmp];i;i=hash[i].next) if(hash[i].val==val) return 1; return 0;}ll DFS(int loc){ ll re=0; for(int i=0;i<26;i++) if(tr[loc][i]) re=re*13131+DFS(tr[loc][i])*(i+628)+i+628; if(tr[loc].end) re=re*13131+1029; if(Query(re)) tot--; else Addhash(re); return re;}int main(){ scanf("%d",&n); for(int now,i=1;i<=n;i++) { scanf("%s",buf);len=strlen(buf); now=0; for(int x,j=0;j<len;j++) { x=buf[j]-'a'; if(!tr[now][x]) tr[now][x]=++tot; now=tr[now][x]; } tr[now].end=1; } DFS(0); printf("%d\n",tot+1); return 0;}
0 0
- BZOJ 2537 [neerc2007]Language Recognition Trie树 树Hash
- Gym 100273L Language Recognition(Trie+Hash)
- BZOJ 2251 Trie树
- BZOJ 4260 trie树
- Trie: 树模样的hash?
- hash和trie树概念
- BZOJ 3012 [Usaco2012 Dec]First! wzq脑洞hash树(正解trie树)
- Language of FatMouse(trie树)
- bzoj 3689 trie树+堆
- Hash树Trie树详解及其应用
- ZOJ 1109 Language of FatMouse (trie树)
- zoj 1109 Language of FatMouse(字典树Trie)
- zoj 1109 Language of FatMouse (字典树Trie)
- BZOJ 3224 普通平衡树 Trie树
- BZOJ 4260: Codechef REBXOR|Trie树
- bzoj 1212 L语言 DP+Trie树
- bzoj 3217: ALOEXT 替罪羊树套trie
- Hash树(散列树)和Trie树(字典树、前缀树)
- log4j slf4j
- extjs datefield 设置显示和编辑格式为‘Y-m-d’
- 从零开始学习SLAM
- 自拉比赛B题(区间更新)
- 操作系统概述
- BZOJ 2537 [neerc2007]Language Recognition Trie树 树Hash
- 第一篇文章
- dnf whatprovides /usr/bin/lxc-ls
- JZOJ 3547【清华集训2014】mex
- 大牛们的浓咖啡(Espresso)简单介绍
- make对命令返回值的检测
- Simultaneous Localization and Mapping (SLAM)讲义1
- AsyncTask异步交互
- 鹅厂狂想曲