ACM ICPC World Finals 2008

Problem I: Password Suspects

One possible solution is by dynamic programming: given that we are at position pos in the password, have already matched the subset S of substrings, and the most recent x characters were the first x characters of pattern P, how many ways are there to fill in the rest of the password? Here, it is important that x is as large as possible, i.e., that there is no y > x and pattern Q such that the y most recent letters match the y first letters of Q.

When implemented right, this gives a time complexity of O(Σ · L · N · M · 2 M ), where L is the maximum length of a word, and Σ is the alphabet size. The optimization needed to achieve this complexity is to precompute what happens when a new character c is added, for all combinations of x, P and c.