P1. [18 marks] In this question, you will implement the dynamic programming algorithm for STRING EDITING, defined as follows:
Input: A source string $S$, a target string $T$, and integer costs $c_a$ for addition, $c_d$ for deletion, and $c_s$ for substitution
Output: The lowest cost of any editing sequence that can be used to edit $s$ into $t$
For example, we can edit the string cats into the string chats by a single addition (of h), into the string cat by a single deletion (of s), and into the string cots by a single substitution (of a into o). We could also edit cats into cots by a deletion (of a) followed by an addition (of o). If $c_a = 1$, $c_d = 2$, and $c_s = 10$, using one deletion and one addition would have a total cost of $c_d + c_a = 3$, which would be cheaper than a substitution at a cost of $c_s = 10$.
The problem can be solved using dynamic programming, where $C[i, j]$ is defined as the minimum cost to edit $S[: i]$ into $T[: j]$. The following facts can be used:
* If $S[i - 1] = T[j - 1]$, then $C[i, j] = C[i - 1, j - 1]$.
* Otherwise, $C[i, j] = \min\{C[i - 1, j - 1] + c_s, C[i - 1, j] + c_d, C[i, j - 1] + c_a\}$
Write a function string_edit that consumes two strings source and target and integers add_cost, delete_cost, and sub_cost and produces the cheapest cost of an edit sequence from source to target. Your function must use dynamic programming.
For full marks, you must use grids. To use the module grids.py, use the line from grids import *; do not include the code for grids.py directly in the file you submit.
Submit your work in a file with the name stringedit.py.