标签:bit ret class name return its amp main col
字典树的包含与不包含关系
#include<bits/stdc++.h> using namespace std; int trie[400100][10]; int sum[400100]; int pos=0; bool insert1( char *word ) { int root=0; for(int i=0;i<strlen(word);i++) { int ch=word[i]-‘0‘; if(trie[root][ ch ]==0) trie[root][ ch ]=++pos; if(sum[root]==2&&root!=0)return false; sum[root]=1; root=trie[root][ch]; } if(sum[root]!=1) sum[root]=2; else return false; return true; } int main() { int cas;scanf("%d",&cas); while(cas--) { pos=0; int n; memset(sum,false,sizeof(sum)); memset(trie,0,sizeof(trie)); char word[11]; scanf("%d",&n); int ok=1; while(n--) { scanf("%s",word); if(ok==0)continue; if(!insert1(word)){ok=0;} } if(ok)printf("YES\n"); else printf("NO\n"); } }
标签:bit ret class name return its amp main col
原文地址:https://www.cnblogs.com/bxd123/p/10342842.html