-
Notifications
You must be signed in to change notification settings - Fork 14
/
10405.cpp
27 lines (26 loc) · 845 Bytes
/
10405.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
#include<iostream>
#include<vector>
using namespace std;
int main(){
string row, col;
while(getline(cin,row) && getline(cin,col)){
int m, n;
m=row.length();
n=col.length();
int i, j;
int tower[m+1][n+1];
for(i=0; i<m+1; i++)
tower[i][0]=0;
for(j=0; j<n+1; j++)
tower[0][j]=0;
for(i=1; i<m+1; i++){
for(j=1; j<n+1; j++){
if(row[i-1] == col[j-1])
tower[i][j] = tower[i-1][j-1] + 1;
else
tower[i][j] = max(tower[i-1][j], tower[i][j-1]);
}
}
cout<<tower[m][n]<<endl;
}
}