-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEditdis.cpp
47 lines (39 loc) · 997 Bytes
/
Editdis.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mod 1000000007
#define ll long long int
#define mk make_pair
#define pb push_back
#define xx first
#define yy second
double pi=3.141592653589793238;
const int M = 1e9+7;
const int Nmax=5005;
const int MM = 1e7+1;
const int N=200010;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int T=1;
//cin>>T;
while(T--){
string a,b;
cin>>a>>b;
int aa=a.size();
int bb=b.size();
vector<vector<int>> dp(aa+1, vector<int>(bb+1,1e9));
dp[0][0]=0;
for(int i=0;i<=aa;i++){
for(int j=0;j<=bb;j++){
if(i)dp[i][j]=min(dp[i][j],dp[i-1][j]+1);
if(j)dp[i][j]=min(dp[i][j],dp[i][j-1]+1);
if(i && j) dp[i][j]=min(dp[i][j],dp[i-1][j-1]+(a[i-1]!=b[j-1]));
}
}
cout<<dp[aa][bb]<<"\n";
}
return 0;
}