#K69592. String Transformation within Limited Operations
String Transformation within Limited Operations
String Transformation within Limited Operations
You are given two strings s
and t
, and an integer k
. Your task is to determine whether it is possible to transform string s
into string t
using at most k
edit operations. The allowed edit operations are insertion, deletion, and substitution.
The problem can be modeled using the concept of the edit distance between two strings. In other words, if the minimum number of operations required to convert s
to t
(denoted as \(d(s,t)\)) satisfies \(d(s,t) \le k\), then the transformation is possible. Otherwise, it is not.
Note: If both strings are identical but non-zero operations are allowed, the transformation is still considered possible.
The edit distance is computed using the following recurrence: \[ \text{dp}[i][j] = \begin{cases} j & \text{if } i = 0, \\ i & \text{if } j = 0, \\ \text{dp}[i-1][j-1] & \text{if } s[i-1] = t[j-1], \\ 1 + \min\{\text{dp}[i-1][j-1],\, \text{dp}[i-1][j],\, \text{dp}[i][j-1]\} & \text{otherwise.} \end{cases} \]
inputFormat
The input is read from stdin and contains three lines:
- The first line contains the source string
s
. - The second line contains the target string
t
. - The third line contains an integer
k
representing the maximum number of allowed edit operations.
outputFormat
Output to stdout a single integer: 1
if the transformation is possible within k
operations, or 0
otherwise.
abcdef
azced
3
1
</p>