Problem Statement
Edit Distance
Implementation
void solve()
{
string s, t;
cin >> s >> t;
ll n = sz(s), m = sz(t);
vvll dp(n + 1, vll(m + 1, inf));
dp[0][0] = 0;
FOR(i, 1, n)
dp[i][0] = i;
FOR(j, 1, m)
dp[0][j] = j;
FOR(i, 1, n)
{
FOR(j, 1, m)
{
if (s[i - 1] == t[j - 1])
{
dp[i][j] = min(dp[i][j], dp[i - 1][j - 1]);
}
dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);
dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1);
dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + 1);
}
}
debug(dp);
cout << dp[n][m] << "\n";
}