Created
October 3, 2015 05:42
-
-
Save ctylim/8f8bcbd0dc567ce6e00a to your computer and use it in GitHub Desktop.
yukicoder No.225
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <iomanip> | |
#include <vector> | |
#include <algorithm> | |
#include <numeric> | |
#include <functional> | |
#include <cmath> | |
#include <queue> | |
#include <stack> | |
#include <set> | |
#include <map> | |
#define repd(i,a,b) for (int i=(a);i<(b);i++) | |
#define rep(i,n) repd(i,0,n) | |
typedef long long ll; | |
using namespace std; | |
int inputValue(){ | |
int a; | |
cin >> a; | |
return a; | |
}; | |
template <typename T> | |
void output(T a, int precision) { | |
if(precision > 0){ | |
cout << setprecision(precision) << a << "\n"; | |
} | |
else{ | |
cout << a << "\n"; | |
} | |
} | |
int main() { | |
// source code | |
int n = inputValue(); | |
int m = inputValue(); | |
string s, t; | |
cin >> s >> t; | |
vector<vector<int>> dp(n + 1, vector<int> (m + 1, 0)); | |
rep(i, n + 1){ | |
dp[i][0] = i; | |
} | |
rep(j, m + 1){ | |
dp[0][j] = j; | |
} | |
rep(i, n){ | |
rep(j, m){ | |
int cost = 1; | |
if (s[i] == t[j]) { | |
cost = 0; | |
} | |
dp[i + 1][j + 1] = min(dp[i][j + 1] + 1, min(dp[i + 1][j] + 1, dp[i][j] + cost)); | |
} | |
} | |
output(dp[n][m], 0); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment