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
Aqib Ahmed J: 2016-01-27 17:22:55

AC in one go :) My 2nd DP problem :)

bharadwaj: 2016-01-16 19:13:01

Hi guys, I am getting a WA if I use it in C++ strings... If do it using the char array in C it is being accepted....

Alex-ander007: 2016-01-07 08:06:03

Got AC for bottom-up. TLE for top-down. Why? Also why locally declared array is giving SIGSEGV?

Shantanu Banerjee: 2015-12-24 11:15:52

simple Wagner Algo!

Siddharth Singh: 2015-12-17 13:22:49

My 2nd DP AC , After Many RE(SIGSEGV) , Feels Good <3
AC in one go in 0.16s C++14
Used Top Down Memo Without Global Declaration
set size of both strings =2101
and take 2d array dp[2101][2101] *BOTH As GLOBAL* to avoid RE

Last edit: 2015-12-17 15:40:31
Shubham Verma: 2015-12-15 20:29:32

In top down approach initialize 2d array of 2101*2101 to get AC else u will get RTE(SIGSEGV) .. :)

Junaid: 2015-12-15 12:14:47

My 2nd DP problem....took time to think...but finally AC in one go....;)

BALMUKUND SINHA: 2015-12-06 18:46:23

why declaring globally remove sigsegv error

bruzelee: 2015-12-01 14:44:11

use bottomup approach it will pass
topdown =tle

vedang: 2015-11-25 22:18:04

can anyone explain why does it give a SIGSEGV error on declaring the 2D array inside a function?


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