Inverting Strings ( Shortest Path )

Правка en1, от UmCaraLegal, 2017-09-19 03:07:48

Hi everyone.

The problem is given 3 strings I, S, F How many moves (it should be minimum) are needed to transform String I to string S and transform string S to string F.

A move on a string S consists of choosing two integers i, j (0 <= i <= j <= | S |) and inverting this substring. For example: S = ABCDE . If i = 1 and j = 4, the string will be DCBAE

Input:

The input consist of 3 strings I, S, F

|I| <= 10 **** |I| = |S| = |F|

Example:

abc cba cab

The output should be 2


I was trying to solve it using a BFS but I think it will get TLE because the worst case will exist N! strings and for every string I need to choose two elements to invert

Anyone have any idea how to solve it ? :D

Теги strings, inversions, dijkstra, dynamic programming, backtracking, brute force

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский UmCaraLegal 2017-09-19 03:07:48 827 Initial revision (published)