| Time Limit: 5000MS | Memory Limit: 65536K | |
| Total Submissions: 3112 | Accepted: 1002 |
Description
A substring of a string T is defined as:
T( i, k)= TiTi +1... Ti+k -1, 1≤ i≤ i+k-1≤| T|.
Given two strings A, B and one integer K, we define S, a set of triples (i, j, k):
S = {( i, j, k) | k≥ K, A( i, k)= B( j, k)}.
You are to give the value of |S| for specific A, B and K.
Input
The input file contains several blocks of data. For each block, the first line contains one integer K, followed by two lines containing strings A and B, respectively. The input file is ended by K=0.
1 ≤ |A|, |B| ≤ 105
1 ≤ K ≤ min{|A|, |B|}
Characters of A and B are all Latin letters.
Output
For each case, output an integer |S|.
Sample Input
2 aababaa abaabaa 1 xx xx 0
Sample Output
22 5
Source
本文介绍了一种高效的字符串匹配算法,用于解决两个字符串中长度至少为K的共有子串问题。通过使用高级的数据结构和栈扫描技术,该算法能够在较短时间内找到所有符合条件的子串。
231





