-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10405.cpp
More file actions
42 lines (40 loc) · 728 Bytes
/
10405.cpp
File metadata and controls
42 lines (40 loc) · 728 Bytes
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
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
string a,b;
int sa,sb;
while(getline(cin,a)){
getline(cin,b);
a=" "+a;
b=" "+b;
sa=a.length();
sb=b.length();
int dp[sa][sb];
for (int i = 0; i < sa; ++i)
{
for (int j = 0; j < sb; ++j)
{
dp[i][j]=0;
}
}
//cout<<a<<endl<<b<<endl;
for (int i = 1; i < sa; ++i)
{
for (int j = 1; j < sb; ++j)
{
int now=0;
if (a[i]==b[j])
{
dp[i][j]=max(dp[i-1][j],max(dp[i][j-1],dp[i-1][j-1]+1));
}
else{
dp[i][j]=max(dp[i-1][j],max(dp[i][j-1],dp[i-1][j-1]));
}
//printf("i==%d ,j==%d dp=%d\n",i,j,dp[i][j] );
}
}
printf("%d\n",dp[sa-1][sb-1] );
}
return 0;
}