-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhdu1159.cpp
More file actions
42 lines (41 loc) · 704 Bytes
/
Copy pathhdu1159.cpp
File metadata and controls
42 lines (41 loc) · 704 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<iostream>
#include<string.h>
using namespace std;
int dp[1001][1001];
int main(){
char a[1001],b[1001];
while(cin>>a>>b){
memset(dp,0,sizeof(dp));
int an=0,bn=0;
while(a[an]!='\0')
an++;
while(b[bn]!='\0')
bn++;
for(int i=0;i<an;i++){
if(a[i]==b[0]){
for(int j=i;j<an;j++){
dp[j][0]=1;
}
break;
}
}
for(int i=0;i<bn;i++){
if(b[i]==a[0]){
for(int j=i;j<bn;j++){
dp[0][j]=1;
}
break;
}
}
for(int i=1;i<an;i++){
for(int j=1;j<bn;j++){
if(a[i]==b[j]){
dp[i][j]=max(dp[i-1][j-1]+1,max(dp[i-1][j],dp[i][j-1]));
}else{
dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
}
}
}
cout<<dp[an-1][bn-1]<<endl;
}
}