KirinrikiTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 833 Accepted Submission(s): 327
Problem Description
We define the distance of two strings A and B with same length n is
disA,B=∑i=0n−1|Ai−Bn−1−i| The difference between the two characters is defined as the difference in ASCII. You should find the maximum length of two non-overlapping substrings in given string S, and the distance between them are less then or equal to m.
Input
The first line of the input gives the number of test cases T; T test cases follow.
Each case begins with one line with one integers m : the limit distance of substring. Then a string S follow. Limits T≤100 0≤m≤5000 Each character in the string is lowercase letter, 2≤|S|≤5000 ∑|S|≤20000
Output
For each test case output one interge denotes the answer : the maximum length of the substring.
Sample Input
Sample Output
Source
思路:
枚举每个位置作为分割两个字串的中点,特别注意有奇数与偶数的区别。
|
KirinrikiTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 833 Accepted Submission(s): 327
Problem Description
We define the distance of two strings A and B with same length n is
disA,B=∑i=0n−1|Ai−Bn−1−i| The difference between the two characters is defined as the difference in ASCII. You should find the maximum length of two non-overlapping substrings in given string S, and the distance between them are less then or equal to m.
Input
The first line of the input gives the number of test cases T; T test cases follow.
Each case begins with one line with one integers m : the limit distance of substring. Then a string S follow. Limits T≤100 0≤m≤5000 Each character in the string is lowercase letter, 2≤|S|≤5000 ∑|S|≤20000
Output
For each test case output one interge denotes the answer : the maximum length of the substring.
Sample Input
Sample Output
Source
|