[BOJ] 5582 공통 부분 문자열

Time Lapse :9min 10sec

5582.cpp

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
using namespace std;
short dp[4001][4001], ans;
int main(){
string a, b;
cin>>a>>b;
for(int i = 1; i <= a.length(); i++)
for(int j = 1; j <= b.length(); j++)
if(a[i-1] == b[j-1])
ans=max(ans, dp[i][j] = dp[i-1][j-1] + 1);
printf("%d",ans);
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/09/02/PS/BOJ/5582/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.