feat: new problem formatted
This commit is contained in:
32
edit-distance/src/TLE.cpp
Normal file
32
edit-distance/src/TLE.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int solve(string &w1, string &w2, int i = 0, int j = 0)
|
||||
{
|
||||
if (i >= w1.size())
|
||||
{
|
||||
return w2.size() - j;
|
||||
}
|
||||
if (j >= w2.size())
|
||||
{
|
||||
return w1.size() - i;
|
||||
}
|
||||
|
||||
if (w1[i] == w2[j])
|
||||
{
|
||||
return solve(w1, w2, i + 1, j + 1);
|
||||
}
|
||||
|
||||
return min({solve(w1, w2, i + 1, j), solve(w1, w2, i + 1, j + 1), solve(w1, w2, i, j + 1)}) + 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int n, m;
|
||||
cin >> n >> m;
|
||||
string w1, w2;
|
||||
cin >> w1 >> w2;
|
||||
cout << solve(w1, w2) << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user