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
2013-01-17 10:54:12 Chetan sharma
I ma getting NZEC in python. I have made all possible changes that could be made to avoid NZEC. Could any please suggest. I don't know if I can paste my code here.
2012-12-27 12:53:15 ron2794
yup.. seg fault problem is solved by taking the array as global and static int.
but i didn't get it, why this happened, why the problem solved this way ?
2012-12-05 20:20:30 Gunjit

use global array ...

Last edit: 2012-12-05 20:22:49
2012-11-19 08:41:54 Paul Draper
Simón Murillo Gómez and others, I depended on string length no more than 2000 and got AC
2012-10-20 05:17:48 Ashok
@:P thanks a lot.
2012-09-28 05:55:40 hot
what will be the answer if any of or both strings are empty...?
2012-07-29 17:14:49 Simón Murillo Gómez
The size is more than 2000.
4 WA before change it to 3000
2012-07-12 07:44:46 i_am_what_i_am
Do we need to convert the string into uppercase character by our own or is it by default assumed to be in uppercase character
2012-07-02 13:56:29 Surya
@I am back, Nikhar : SIGSEGV is because of the 2D array size if you have used. In case of 2000 length, seg fault. Use static int array with fixed size if required!
2012-07-01 18:44:26 npsabari
wth?? SEG fault again again.. though its working fine in my comp!
@nikhar : did you figure what went wrong?

Atlast!! learnt a new way to solve!!

Last edit: 2012-07-01 21:15:59
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.