The return string is a string. Reading from left to right is the same as reading from right to left, for example, ABA ". Of course, the problem we will give you will not simply judge whether a string is a return string. Now you are asked to give you a string. You can add characters at any position and add at least a few characters to it to make it a return string.
-
-
Input
-
-
The first line is an integer N (0 <n <100)
The next n rows have one character string per line. Each character string cannot exceed 1000 characters in length.
-
-
Output
-
-
Minimum number of characters to be added for output per line
-
-
DP [I] [J] = DP [I + 1] [J] s [I] = s [J]
-
-
Min (DP [I + 1] [J], DP [I] [J + 1]) + 1; (not equal)
-
-
If the length is 2, then 3, and the last length is l, It is the answer.
-
Import Java. util. vendor; Public Class Main { Public Static Void Main (string [] ARGs ){ // Todo auto-generated method stub Scanner SCN = New Using (system. In ); Int Len = SCN. nextint (); While (Len --> 0 ) {String s =SCN. Next (); Int L = S. Length (); Int DP [] [] = New Int [L] [l]; For ( Int I = 1; I <L; I ++ ){ For ( Int J = 0; j <l-I; j ++ ){ If (S. charat (j) = S. charat (J + I) {DP [J] [I + J] = DP [J + 1] [I + J-1 ];} Else {DP [J] [I + J] = math. Min (DP [J] [I + J-1], DP [J + 1] [I + J]) + 1 ; }}} System. Out. println (DP [ 0] L-1 ]) ;}}