Nyoj 37 echo string

Source: Internet
Author: User

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 ]) ;}} 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.