IOI '00 - Beijing, China
PalindromeA palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. You are to write a program which, given a string, determines the minimal number of characters to be inserted into the string in order to obtain a palindrome.
As an example, by inserting 2 characters, the string "Ab3bd" can be transformed into a palindrome ("dAb3bAd" or "Adb3bdA"). However, inserting fewer than 2 characters does not produce a palindrome.
InputThe first line contains an integer N (3 ≤ N ≤ 5000), the length of the input string. The string follows on the next line. The string will be composed of uppercase letters, lowercase letters, and digits. Uppercase and lowercase letters are to be considered distinct.
OutputA single integer, the desired minimal number.
Point Value: 10
Time Limit: 2.00s
Memory Limit: 16M
Added: Aug 22, 2009
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3