-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy path近似串匹配问题.cpp
More file actions
45 lines (44 loc) · 1.05 KB
/
近似串匹配问题.cpp
File metadata and controls
45 lines (44 loc) · 1.05 KB
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
#include<bits/stdc++.h>
using namespace std;
int D[6][9];
int ASM(char P[ ], char T[ ], int m, int n);
int main()
{
char P[]="happy";
char T[]="hsppay";
cout<<ASM(P,T,5,6)<<endl;
return 0;
}
int min(int x,int y,int z)
{
int min;
if (x < y)
min = x;
else
min = y;
if (z < min)
min = z;
return min;
}
int ASM(char P[ ], char T[ ], int m, int n)
{
int i, j;
for (j = 1; j <= n; j++) //初始化第0行
D[0][j] = j;
for (i = 0; i <= m; i++) //初始化第0列
D[i][0] = i;
for (j = 1; j <= n; j++) //根据递推式依次计算每一列
{
for (i = 1; i <= m; i++)
{
if (P[i-1] == T[j-1])
D[i][j] =min(D[i-1][j-1], D[i-1][j]+1, D[i][j-1]+1);
else
D[i][j] = min(D[i-1][j-1]+1, D[i-1][j]+1, D[i][j-1]+1);
}
for (i = 1; i <= m; i++)
cout<<D[i][j]<<" ";
cout<<endl;
}
return D[m][n];
}