DPL_1_E Levenshtein Distance
Table of contents
# Problem
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_E&lang=ja#
# Time complexity
# Solution
#define MAX_S 1001
string S1, S2;
Int dp[MAX_S][MAX_S];
void input() {
cin >> S1 >> S2;
}
void solve() {
loop(c1,0,S1.length()+1) {
loop(c2,0,S2.length()+1) {
if (c1 == 0) dp[c1][c2] = c2;
else if (c2 == 0) dp[c1][c2] = c1;
else if (S1[c1-1] == S2[c2-1]) {
dp[c1][c2] = dp[c1-1][c2-1];
} else {
dp[c1][c2] = 1 + min(min(dp[c1-1][c2], dp[c1][c2-1]), dp[c1-1][c2-1]);
}
}
}
cout << dp[S1.length()][S2.length()] << endl;
}
int main() {
input();
solve();
}
Shun
Remote freelancer. A web and mobile application enginner.
Traveling around the world based on East Asia.
I'm looking forward to your job offers from all over the world!