-
Notifications
You must be signed in to change notification settings - Fork 4
/
dp1- longest common substring.cpp
86 lines (67 loc) · 1.12 KB
/
dp1- longest common substring.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//DP-1 (Longest common substring)
#include<iostream>
using namespace std;
void longestCommonsubstring(string s1,string s2);
void longestCommonsubstring(string s1,string s2)
{
int R= s1.length()+1;
int C= s2.length()+1;
int lcsub[R][C];
for(int i=0;i<R-1;i++)
lcsub[0][i]=0;
for(int j=0;j<C-1;j++)
lcsub[j][0]=0;
for(int i=0;i<R;i++)
{
cout<<endl;
for(int j=0;j<C;j++)
{
cout<<lcsub[i][j];
}
}
/*
int max= INT_MIN;
for(int i=1;i<R;i++)
{
for(int j=1;j<C;j++)
{
if(s1[i]==s2[j])
lcsub[i][j]=lcsub[i-1][j-1]+1;
else
lcsub[i][j]=0;
if(lcsub[i][j]>max)
max=lcsub[i][j];
}
}
for(int i=0;i<R;i++)
{
cout<<endl;
for(int j=0;j<C;j++)
{
cout<<lcsub[i][j];
}
}
int f=1;
for(int i=0;i<R;i++)
{
for(int j=0;j<C;j++)
{
//cout<<lcsub[i][j];
if(lcsub[i][j]==f)
{
// cout<<s1[i];
f++;
if(f==max) break;
}
}
}
// cout<<max+1;
*/
}
int main()
{
string s1="abcdaf";
string s2="bcd";
longestCommonsubstring(s1,s2);
return 0;
}