#P14804. [CCPC 2024 哈尔滨站] 一个朴素的字符串问题
[CCPC 2024 哈尔滨站] 一个朴素的字符串问题
Description
You are given a character grid with rows and columns, where each cell contains a lowercase letter. You can start at any position in the grid and move several steps, with each step either to the right or downward, stopping at any cell. Concatenating the characters from the cells visited in order forms a string.
A string is called a double string if and only if there exists a non-empty string such that . For example, and are double strings, while and are not.
Given the character grid, find the length of the longest double string you can obtain.
Input Format
The first line contains an integer (), representing the number of columns in the character grid.
The next two lines contain two strings of length consisting only of lowercase English letters, representing the character grid.
Output Format
Output a single integer, representing the length of the longest double string you can obtain.
5
abcab
acabc
6
6
babbaa
babaaa
6
2
ne
fu
0
Hint
In the first example, the longest double string can be obtained as follows (not unique):
$$\begin{aligned} \underline{\texttt{abc}}\texttt{ab}\\ \texttt{ac}\underline{\texttt{abc}} \end{aligned}$$
京公网安备 11011102002149号