#include #define rep(i,a,b) for(int i=int(a);i> N >> M >> S >> T; int dp[N+1][M+1] = {}; rep(i,0,N+1)dp[i][0] = i; rep(i,0,M+1)dp[0][i] = i; rep(i,1,N+1)rep(j,1,M+1){ int cost = !(S[i-1] == T[j-1]); dp[i][j] = min({ dp[i-1][j] + 1, dp[i][j-1] + 1, dp[i-1][j-1] + cost }); } cout << dp[N][M] << endl; }