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
2014-02-07 22:56:15 mohamad alshboul
weak test cases !!
some cases isn't covered ex:
BA
BAA
but nice standard DP problem :)
2014-02-07 22:45:20 coldzero
in the test case ABC & AB
the answer should be 1 but in my program it gave 2 and my solution accepted , week test cases but nice DP problem
2014-02-05 20:49:22 JordanBelfort
nice one :)
2014-02-02 11:44:53 Vipul Pandey
dp..
2014-02-01 06:44:41 Kalhan Koul
string size is greater than 2000.Got ac with 3000
2014-01-11 00:29:49 sarelfeniel
My 50th problem :D

Also had to use scanf instead of gets. Frustrating when this happens.

EDIT: But it's fast enough for top 15 so whatever.

Last edit: 2014-01-11 01:50:26
2013-12-24 22:59:20 mateifl

For
AABC
ABC

the right answer is 1, from deleting the first A? Or 3, from replacing AB with BC and deleting C in the first string?
2013-12-20 21:37:17 Abhinav Gupta
hey!!..i am getting segmentation fault..cant get it!! :(...help!!
2013-12-14 11:05:03 ABHISHEK004
GOT ACC using scanf but wrong using gets :/
MY FIRST DP... :D
2013-11-28 06:20:29 Hassassin
@ahmed ameen mohamed
the answer to
1
ALLAHABAD
YATINDRA
is
8 itself!!cost me 1 WA
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.