Problem:
Edit Distance (Levenshtein Distance)

Find the edit distance between given two words s1 and s2.

The disntace is the minimum number of single-character edits required to change one word into the other. The edits including the following operations:

insertion: Insert a character at a particular position.

deletion: Delete a character at a particular position.

substitution: Change the character at a particular position to a different character

Input

s1
s2

Two words s1 and s2 are given in the first line and the second line respectively. The words will consist of lower case characters.

Output

Print the edit distance in a line.

Constraints

1 ≤ length of s1 ≤ 1000

1 ≤ length of s2 ≤ 1000

Sample Input 1

acac
acm

Sample Output 1

2

Sample Input 2

icpc
icpc

Sample Output 2

0

Solution in C (judge verdict: Runtime Error)

#include <stdio.h>
#include <string.h>
#define unknown (-1)

int len(int i, int j); //??¨????????¢????±???????
int min3(int x, int y, int z); //3????????°???????°????????±???????
int M(int i, int j); //0???1???

int PD[1000][1000]; //??????
char s1[1000];
char s2[1000];

int main(void)
{
	unsigned int i, j;
	scanf("%s", s1);
	scanf("%s", s2);
	for (i = 0; i <= strlen(s1); ++i) {
		for (j = 0; j <= strlen(s2); ++j) {
			PD[i][j] = unknown;
		}
	}
	printf("%d\n", len(strlen(s1), strlen(s2)));


    return 0;
}

int len(int i, int j) { //?????°???????????????????¨????????????¨?????????
	int t;
	if (i == 0) {
		PD[0][j] = j;
		return j;
	}
	else if (j == 0) {
		PD[i][0] = i;
		return i;
	}
	if (PD[i][j] != unknown) return PD[i][j];
	t = min3((len(i - 1, j - 1) + M(i-1, j-1)), (len(i - 1, j) + 1), (len(i, j - 1) + 1));
	PD[i][j] = t;
	return t;
}


int min3(int x, int y, int z) {
	int i;
	int num[3];
	num[0] = x;
	num[1] = y;
	num[2] = z;
	int min = x;
	for (i = 0; i < 3; ++i) {
		if (num[i] <= min) {
			min = num[i];
		}
	}
	return min;
}

int M(int i, int j) {
	if (s1[i] == s2[j]) return 0;
	else return 1;
}