Main topic:
Gives a string a, which requires the shortest string b,b not a subsequence. Find the shortest length and shortest number of strings | a|<=105.
Exercises
1. The game did not come out, after one months to see the problem, although retired, or determined to understand it.
2. Basically, the network is directly affixed to the code. I'll write the solution briefly:
We can imagine moving on string a. At the beginning of a starting node (node No. 0), if we select the character P, now on the K node, then we can jump directly to p next occurrence of the position R (if not, jump to n+1 point).
Since K,r have no character p directly, there is no need to consider the points between them.
So F[i] represents the minimum number of steps to move to the point I, and g[i] represents the corresponding number of scenarios. Pre-nxt[i][j] indicates the position of the character J on the leftmost side of a[i+1 ... n]. That is, the edges between nodes.
From I can go directly to nxt[i][j] by selecting the character J. Transfer See code.
1for (int i=1;i<=n+1;i++) f[i]=inf,g[i]=0;2for (int i=0;i<=n;i++)3{4if (F[i]==inf)Continue 5 for (int J=0;j<26;j++) 6 Span style= "color: #000000;" > { 7 if (F[i]+1<f[ NXT[I][J]]) f[nxt[i][j]]=f[i]+1,g[nxt[i][j]]=0; 8 if (f[nxt[i][j]]==f[i]+ 1) G[nxt[i][j]]= 9 }10}
Strongest password (Baidu star rematch T5)