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
2020-01-23 14:58:51
Just use cin instead of getline.I have solved many problem where getline doesn't work but cin does.Mayber they have used space to separate int the test case.
2020-01-19 04:38:36
cin.get() gives WA while scanf gives AC. What is the reason?
2020-01-17 21:11:00
BOOM !!!!
2019-09-28 13:26:37
nothing to worry just declare 2001x2001 global matrix if you are going to use this approach

BTW Good Question
2019-08-15 21:36:37
Even though the input descriptions says that there are 10 test cases. Reading the number of test cases is mandatory. Else, WA !!
2019-05-28 21:23:16 Sergey
All input lines could have "\r\n" sequence at the end, not just '\n' character, be careful with hand-written input and with library-implemented readliners.
2019-04-25 03:37:21
""Declare size of dp matrix as 3000X3000 . I declared it as 2003X2003 and it costs me 3 wrong answers . It sucks !!! "" is misleading.i got an AC @abhi_698
2019-04-21 13:00:20
Declare size of dp matrix as 3000X3000 . I declared it as 2003X2003 and it costs me 3 wrong answers . It sucks !!!
2019-03-01 19:18:30
AC in one go!!
nice problem
2018-12-16 16:42:41
GOT TLE in top-down????But not in bottom up
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.