加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Phone List HDU1671

发布时间:2020-12-14 05:12:42 所属栏目:大数据 来源:网络整理
导读:字典树的包含与不包含关系 #includebits/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 ;istrlen(word);i++ ) { int ch=word[i]- ‘ 0 ‘ ; if (tr

字典树的包含与不包含关系

#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("YESn");
        else printf("NOn");

    }

}
View Code

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读