BOJ : https://www.acmicpc.net/problem/9251

github : https://github.com/junho0956/Algorithm/tree/master/9251

 

LCS에 대한 설명을 포스팅해놓았습니다. 참고하시면됩니다

LCS : https://junho0956.tistory.com/39?category=868069

 

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
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int dp[1001][1001];
 
int main() {
    ios::sync_with_stdio(0), cin.tie(0);
 
    string str1, str2;
    cin >> str1 >> str2;
 
    for (int i = 0; i < str1.length(); i++) {
        for (int k = 0; k < str2.length(); k++) {
            if (str1[i] == str2[k]) dp[i + 1][k + 1= dp[i][k] + 1;
            else dp[i + 1][k + 1= max(dp[i + 1][k], dp[i][k + 1]);
        }
    }
 
    cout << dp[str1.length()][str2.length()];
    return 0;
}
 
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter

'algorithm > BOJ' 카테고리의 다른 글

BOJ 1958번 LCS 3  (0) 2020.02.12
BOJ 9252번 LCS2  (0) 2020.02.12
BOJ 5502번 팰린드롬  (0) 2020.02.12
BOJ 3793번 Common Subsequence  (0) 2020.02.12
BOJ 1365번 꼬인 전깃줄  (0) 2020.02.11

+ Recent posts