본문 바로가기
둥지/알고리즘

[백준 15482]한글 LCS

by 까닭 2023. 6. 19.

문제링크

#include <iostream>
#include <string>

using namespace std;

int LCS[3003][3003];

int main()
{
    string str1 = {};
    string str2 = {};

    cin >> str1 >> str2;

    int n = str1.size();
    int m = str2.size();

    int offset = 3;

    for (int i = 3; i <= n; i += offset)
    {
        for (int j = 3; j <= m; j += offset)
        {
            if (str1.substr(i - 3, offset) == str2.substr(j - 3, offset))
            {
                LCS[i][j] = LCS[i - 3][j - 3] + 1;
            }

            else
            {
                LCS[i][j] = max(LCS[i - 3][j], LCS[i][j - 3]);
            }
        }
    }

    cout << LCS[n][m] << endl;
}

'둥지 > 알고리즘' 카테고리의 다른 글

[백준 15723] n단 논법  (0) 2023.07.14
[백준 11404] 플로이드  (1) 2023.06.09
[백준 11726] 2×n 타일링  (0) 2023.05.26
[프로그래머스] 폰켓몬  (0) 2023.05.08
[프로그래머스] 프로세스  (0) 2023.05.04