307982: CF1446B. Catching Cheaters
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Catching Cheaters
题意翻译
给我们两个字符串,让我们从中选出两个字串,算出它们的最大公共子序列长度。然后将它乘$ 4 $在减去两个字串的长度。问你这个数最大是多少。题目描述
You are given two strings $ A $ and $ B $ representing essays of two students who are suspected cheaters. For any two strings $ C $ , $ D $ we define their similarity score $ S(C,D) $ as $ 4\cdot LCS(C,D) - |C| - |D| $ , where $ LCS(C,D) $ denotes the length of the Longest Common Subsequence of strings $ C $ and $ D $ . You believe that only some part of the essays could have been copied, therefore you're interested in their substrings. Calculate the maximal similarity score over all pairs of substrings. More formally, output maximal $ S(C, D) $ over all pairs $ (C, D) $ , where $ C $ is some substring of $ A $ , and $ D $ is some substring of $ B $ . If $ X $ is a string, $ |X| $ denotes its length. A string $ a $ is a substring of a string $ b $ if $ a $ can be obtained from $ b $ by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end. A string $ a $ is a subsequence of a string $ b $ if $ a $ can be obtained from $ b $ by deletion of several (possibly, zero or all) characters. Pay attention to the difference between the substring and subsequence, as they both appear in the problem statement. You may wish to read the [Wikipedia page about the Longest Common Subsequence problem](https://en.wikipedia.org/wiki/Longest_common_subsequence_problem).输入输出格式
输入格式
The first line contains two positive integers $ n $ and $ m $ ( $ 1 \leq n, m \leq 5000 $ ) — lengths of the two strings $ A $ and $ B $ . The second line contains a string consisting of $ n $ lowercase Latin letters — string $ A $ . The third line contains a string consisting of $ m $ lowercase Latin letters — string $ B $ .
输出格式
Output maximal $ S(C, D) $ over all pairs $ (C, D) $ , where $ C $ is some substring of $ A $ , and $ D $ is some substring of $ B $ .
输入输出样例
输入样例 #1
4 5
abba
babab
输出样例 #1
5
输入样例 #2
8 10
bbbbabab
bbbabaaaaa
输出样例 #2
12
输入样例 #3
7 7
uiibwws
qhtkxcn
输出样例 #3
0