|
||||||||||
Jumping RobotTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 183 Accepted Submission(s): 7 Problem Description Ali invents a jumping robot. This robot is controlled by a program {Di}, which is a finite sequence of non-negative ¡°jumping distances¡±. The program can¡¯t be changed once the robot is made. There are L boxes in a line. Each time the robot is placed in one of the boxes, facing left or right, and then it is turned on. It first jumps over D1 boxes, then jumps over D2 boxes ... Ali writes a capital letter in each box. The robot prints out all the letter it touches, including the initial one. Now he wants to design a program with a length of p, so that for every kind of letters in the boxes, if you carefully choose the initial position and direction of the robot, it can print out a sequence of that letter of length p. What¡¯s the maximum possible p for the given letters in boxes? Input The input consists several testcases. The first line contains 2 integers n (4 <= n <= 8) and L (4 <= L <= 100), represents the number of different capital letters and the number of boxes. The second line contains a string whose length is exactly L, represents the letters in each box. The string only contains the first n capital letters, and each letter appears at least once in the string. Output Print an integer, the maximum length of the jumping program. Sample Input
Sample Output
Source | ||||||||||
|