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
mohamad alshboul: 2014-02-07 22:56:15

weak test cases !!
some cases isn't covered ex:
BA
BAA
but nice standard DP problem :)

coldzero: 2014-02-07 22:45:20

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

JordanBelfort: 2014-02-05 20:49:22

nice one :)

Vipul Pandey: 2014-02-02 11:44:53

dp..

Kalhan Koul: 2014-02-01 06:44:41

string size is greater than 2000.Got ac with 3000

sarelfeniel: 2014-01-11 00:29:49

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
mateifl: 2013-12-24 22:59:20


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?

Abhinav Gupta: 2013-12-20 21:37:17

hey!!..i am getting segmentation fault..cant get it!! :(...help!!

ABHISHEK004: 2013-12-14 11:05:03

GOT ACC using scanf but wrong using gets :/
MY FIRST DP... :D

Hassassin: 2013-11-28 06:20:29

@ahmed ameen mohamed
the answer to
1
ALLAHABAD
YATINDRA
is
8 itself!!cost me 1 WA


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