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
2015-01-22 06:29:02 Kaustubh Mallik
Even 2D array solution is accepted. :D
2015-01-18 16:59:55 Takanori MAEHARA
@simple
My 0.02s solution is a bit-parallel algorithm. see http://www.sis.uta.fi/~hh56766/pubs/psc02.pdf
2014-10-18 08:39:53 Infinity
my time 1.21
best time 0.1 and 0.5
I WOULD like to know your approach.

Last edit: 2014-10-18 08:40:46
2014-10-05 23:52:48 mandu_ism
Made a mistake in calculating min!!

I need sleep :(
2014-09-29 10:48:32 mayank
There is no need for 1D array, in C++ at least. :)
2014-09-24 05:12:50 Trương Ngọc Duy
Edit size MAX 3000 ... NOT 2000!
2014-09-24 05:07:37 Trương Ngọc Duy
How to using 1D ??? help me !
2014-09-20 16:50:56 bhumik
What is answer for
1
SATURDAY
SUNDAY

My solution which got AC gave 7 as output but ans should be 3 as we can delete 'A' and 'T' from SATURDAY and then convert 'R' to 'N'.
2014-09-13 07:11:37 deCodeIt
gave SIGSEV error with 2D array... as memory exceeded.. But worked awesome with 1D.... :) (y)
2014-08-17 13:53:40 mitz
good one!!!
use 1D array in c

Last edit: 2014-08-17 13:54:40
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.