F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Jumping Robot

Time 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
4 15 DABCDDCCBAACBBA
 

Sample Output
3
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 18:34:33, Gzip enabled