EDIST - Edit distance

You are given two strings, A and B. Answer, what is the smallest number of operations you need to
transform A to B?

Operations are:

  1. Delete one letter from one of strings
  2. Insert one letter into one of strings
  3. Replace one of letters from one of strings with another letter

Input

T - number of test cases

For each test case:

  • String A
  • String B

Both strings will contain only uppercase characters and they won't be longer than 2000 characters. 

There will be 10 test cases in data set.

Output

For each test case, one line, minimum number of operations.

Example

Input:
1
FOOD
MONEY

Output:
4

Added by:Mislav Balunović
Date:2010-02-28
Time limit:15s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS OBJC PERL6 SQLITE VB.NET
Resource:Internet

hide comments
2014-07-24 23:09:01 beginner
easy one.
my 50th ac!!
2014-07-19 14:22:57 Ankit Aggarwal
use dynamic memory allocation!!
2014-07-08 10:32:44 Rajat (1307086)
Famous Levenshtein distance problem.
One of best question for dynamic programming intro.Read more of it at
en.m.wikipedia.org/wiki/Levenshtein_distance
2014-07-03 19:16:48 excursionist
my 100th :D
2014-06-20 08:25:20 Atreyee
Getting TLE even after doing it by DP :(
2014-06-10 13:39:56 Vikas Yadav
nice dp prob, AC in 1 go :-)
2014-06-07 16:09:24 fallacy
TLE :( ?
2014-06-05 11:18:37 sanban
For
1
ALLAHABAD
YATINDRA
shouldn't the ans be 6??
as we can add an A and then replace the remaining Y,T,I,N,R with A,L,L,H,B...making it six steps
2014-05-21 11:51:59 Agam Gupta
got AC :)

Last edit: 2014-05-21 12:20:01
2014-03-30 07:57:57 Rishav Goyal
i bet my sol is correct.!!
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.