#C429. Edit Distance Transformation
Edit Distance Transformation
Edit Distance Transformation
This problem requires you to compute the minimum number of operations required to transform one string into another using three permitted operations: insertion, deletion, and substitution. This is a classic edit distance problem that can be solved using dynamic programming.
The state transition can be described using the formula:
\[ dp[i][j] = \begin{cases} j, & \text{if } i = 0 \\ i, & \text{if } j = 0 \\ dp[i-1][j-1], & \text{if } s_1[i-1]=s_2[j-1] \\ 1+\min\{dp[i-1][j],\, dp[i][j-1],\, dp[i-1][j-1]\}, & \text{otherwise} \end{cases} \]
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains the string
s1
. - The second line contains the string
s2
.
Both strings may be empty.
outputFormat
Output to standard output (stdout) a single integer representing the minimum number of operations required to convert s1
into s2
.
abcd
bcf
2