Codeforces Round #291 (Div. 2)C.Watto and Mechanism——字典树+dfs
来源:互联网 发布:知乎女神王珏 编辑:程序博客网 时间:2024/05/21 15:50
http://codeforces.com/contest/514
n个字符串m个询问,判断询问的字符串能否通过修改其中的一个字符使得变成给定的n个字符串中的某一个
注意:必须修改一个字符
#include<bits/stdc++.h>const int maxnode=6e5+100;const int sigma_size=3;using namespace std;int n,m;int ch[maxnode][sigma_size],val[maxnode];int sz;void init(){ memset(ch,0,sizeof ch); memset(val,0,sizeof(val)); sz=1;}void insert(char *s){ int u=0,l=strlen(s); for(int i=0; i<l; ++i) { int c=s[i]-'a'; if(!ch[u][c]) { ch[u][c]=sz++; } u=ch[u][c]; } val[u]=1;}char s[maxnode];bool dfs(char *s,int rt,int p,int d,int l){ if(d>1) return false; if(p==l){ if(d==1&&val[rt]) return true; return false; } for(int i=0;i<sigma_size;++i){ if(ch[rt][i]){ if(dfs(s,ch[rt][i],p+1,d+(i!=s[p]-'a'),l)) return true; } } return false;}int main(){ init(); scanf("%d%d",&n,&m); for(int i=0; i<n; ++i) { scanf("%s",s); insert(s); } for(int i=0; i<m; ++i) { scanf("%s",s); if(dfs(s,0,0,0,strlen(s))) printf("YES\n"); else printf("NO\n"); } return 0;}
0 0
- Codeforces Round #291 (Div. 2)C.Watto and Mechanism——字典树+dfs
- Codeforces Round #291 (Div. 2) C. Watto and Mechanism Trie字典树+dfs
- C. Watto and Mechanism 字典树 Codeforces Round #291 (Div. 2)
- Codeforces Round #291 (Div. 2)---C. Watto and Mechanism
- Codeforces Round #291 (Div. 2) -- C. Watto and Mechanism
- Codeforces Round #291 (Div. 2) C. Watto and Mechanism
- Codeforces Round #291 (Div. 2) C - Watto and Mechanism
- Codeforces Round #291 (Div. 2) C. Watto and Mechanism
- Codeforces Round #291 (Div. 2) C Watto and Mechanism
- Codeforces Round #291 (Div. 2) 514C Watto and Mechanism
- 字典树(+DFS)——Watto and Mechanism ( CodeForces 514C )
- Codeforces 514C Watto and Mechanism (字典树+dfs)
- Trie树 Codeforces Round #291 (Div. 2) C. Watto and Mechanism
- Codeforces Round #291 (Div. 2)-C. Watto and Mechanism(Trie树)
- codeforces C. Watto and Mechanism 字典树
- Codeforces Round #291 (Div. 2) C. Watto and Mechanism hash函数
- C. Watto and Mechanism(字典树加dfs)
- coderforce 514C - Watto and Mechanism(字典树+dfs)
- Codeforces Round #292 (Div. 1) B. Drazil and Tiles(拓扑排序)
- TRIZ随记(2)
- UIReferenceLibraryViewController的使用(调用系统词典)
- Emacs markdown mode C-c C-c p预览中文乱码
- HDU 1596 find the safest road
- Codeforces Round #291 (Div. 2)C.Watto and Mechanism——字典树+dfs
- 一种基于穷举碰撞的RSA降维破解算法
- Android 自己试验Ip地址的时候,不要用localhost 要用ipconfig 进行查 IPV4
- POJ3905 Perfect Election【2-SAT】【Tarjan】
- Android Studio(01)——导入外部引用Library
- C# 深入理解按位异或运算符^
- ScrollView嵌套ListView只显示一行的问题
- 获取UIView所在的视图控制器(UIViewController)
- 中国:阿里、腾讯与微博:移动支付的新三国演义,美国:三星收购美移动支付服务LoopPay与苹果争抢未来移动支付市场