标签:字符 条件 emc topsort 之间 class span max strlen
题目大意:
首先,我们来定义一下淋漓尽致子串。
#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int maxn = 1e5 + 100; const int maxn2 = maxn*2; int cnt = 1, last = 1; int endpos[maxn2], tr[maxn2][30], par[maxn2], mx[maxn2], c[maxn2], id[maxn2], f[maxn2]; int n; char s[maxn]; void extend(int x){ int np = ++cnt, p = last; endpos[np] = 1; mx[np] = mx[p] + 1; last = np; while(p && !tr[p][x]) tr[p][x] = np, p = par[p]; if(!p) par[np] = 1; else { int q = tr[p][x]; if(mx[q] == mx[p]+1) par[np] = q; else { int nq = ++cnt; mx[nq] = mx[p]+1; memcpy(tr[nq], tr[q], sizeof(tr[q])); par[nq] = par[q]; par[q] = par[np] = nq; while(p && tr[p][x] == q) tr[p][x] = nq, p = par[p]; } } } void topsort(){ for(int i = 1; i <= cnt; i++) c[mx[i]]++; for(int i = 1; i <= n; i++) c[i] += c[i-1]; for(int i = 1; i <= cnt; i++) id[c[mx[i]]--] = i; for(int i = cnt; i; i--) endpos[par[id[i]]] += endpos[id[i]]; } int main() { cin>>s; n = strlen(s); for(int i = 0; i < n; i++) extend(s[i]-‘a‘); topsort(); endpos[0] = 0; for(int i = cnt; i; i--) if(endpos[id[i]] > 1) f[par[id[i]]] = 1; for(int i = 1; i <= cnt; i++) if(endpos[i] <= 1) f[i] = 1; for(int i = 1; i <= cnt; i++) for(int c = 0; c < 26; c++) if(endpos[tr[i][c]] > 1){ f[i] = 1; break; } int ans = 0; for(int i = 2; i <= cnt; i++) if(!f[i]) ans++; cout<<ans<<endl; return 0; }
标签:字符 条件 emc topsort 之间 class span max strlen
原文地址:http://www.cnblogs.com/Saurus/p/7593092.html