Strongest password (Baidu star rematch T5)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.