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

hide comments
sangmai: 2020-01-19 04:38:36

cin.get() gives WA while scanf gives AC. What is the reason?

deadly_sec: 2020-01-17 21:11:00

BOOM !!!!

manuver: 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

riyaganiga: 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 !!

Sergey: 2019-05-28 21:23:16

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.

gaurav1614: 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

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 !!!

spojwithsaurav: 2019-03-01 19:18:30

AC in one go!!
nice problem

rajat__: 2018-12-16 16:42:41

GOT TLE in top-down????But not in bottom up

double_0_seven: 2018-10-25 00:38:20

AC in one go..!!!


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