struct Trie{ int ch[maxnnode][sigma_size]; int val[maxnnode]; int sz; Trie(){sz=1;memset(ch[0],0,sizeof(ch[0]));} int idx(char c) {return c-‘a‘;} void Insert(char *s,int v){ int u=0,n=strlen(s); for(int i=0;i<n;i++) { int c=idx(s[i]); if(!ch[u][c]){ memset(ch[sz],0,sizeof(ch[sz])); val[sz]=0; ch[u][c]=sz++; } u=ch[u][c]; } val[u]=v; } bool Find(char* s) { int u=0,n=strlen(s); for(int i=0;i<n;i++) { int c=idx(s[i]); if(!ch[u][c]) return false; u=ch[u][c]; } return true; } };
题目:
UVALive3942 Remember the Word
UVA11732 "strcmp()" Anyone?
UVA11488 Hyper Prefix Sets
UVALive3703 Billing Tables
时间: 2024-11-07 02:36:27