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
meghamittal92: 2015-07-31 14:28:50

Getting wrong ans with string and getline whereas AC with char array and scanf :??

iammangod96: 2015-07-26 21:43:57

Use Wagner-Fischer algorithm directly.
If you are getting segmentation fault then please use static keyword for declaring the 2-d array.

maan_j: 2015-07-24 19:34:26

top down + memo =tle
dp:)

divp: 2015-07-20 14:37:56

Dp :p 0.48 sec in JAVA ;p

anavgupta31: 2015-07-18 12:42:29

can I have some test cases...?

Akshay Aradhya: 2015-07-17 12:49:06

Dont understand how the Problem title relates with the problem

moaz_eldefrawy: 2015-07-10 03:26:03

to convert FOOD to MONEY . is just 2 steps . because you can just sell it :D :D . by giving the food and taking the money :).

mohit: 2015-07-02 09:11:16

"https://en.wikipedia.org/wiki/Levenshtein_distance" Iterative with full matrix.. global var for matrix a must

Last edit: 2015-07-02 09:21:24
Kartik: 2015-07-01 10:29:34

@manish sombansh: try 2001, because last character is always reserved for '\0'

Manish Sombansh: 2015-06-15 20:33:14

Use global array and string array size of 3000. A size of 2000 is giving runtime error in C.


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