类似phonelist 一次ac
判断失败主要有两个要点
1. 是否包含了某段的结尾结点 说明某段被此段包含
2.此段的结尾结点是否为某段的痕迹 说明此段被包含
#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() { char word[10];int cas=0; while(gets(word)) { int ok=1; memset(sum,0,sizeof(sum)); memset(trie,0,sizeof(trie)); if(!insert1(word)){ok=0;} while(gets(word)&&word[0]!='9') { if(ok==0)continue; if(!insert1(word)){ok=0;} } if(ok)printf("Set %d is immediately decodable ",++cas); else printf("Set %d is not immediately decodable ",++cas); } }