๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm ๐Ÿง‘๐Ÿป‍๐Ÿ’ป/๋ฐฑ์ค€(BOJ)

[๋ฐฑ์ค€,c++] 15482๋ฒˆ - ํ•œ๊ธ€ LCS

by dkswnkk 2021. 11. 17.

๋ฌธ์ œ

 

15482๋ฒˆ: ํ•œ๊ธ€ LCS

์ฒซ์งธ ์ค„๊ณผ ๋‘˜์งธ ์ค„์— ๋‘ ๋ฌธ์ž์—ด์ด ์ฃผ์–ด์ง„๋‹ค. ๋ฌธ์ž์—ด์€ ์ตœ๋Œ€ 1000๊ธ€์ž์ด๊ณ , ์œ ๋‹ˆ์ฝ”๋“œ U+AC00(๊ฐ€)๋ถ€ํ„ฐ U+D7A3(ํžฃ)๊นŒ์ง€๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ์œผ๋ฉฐ, UTF-8๋กœ ์ธ์ฝ”๋”ฉ ๋˜์–ด ์žˆ๋‹ค.

www.acmicpc.net

 

์ฝ”๋“œ

#include <iostream>
using namespace std;

int dp[3001][3001];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    string A,B; cin>>A>>B;
    
    for(int i=3; i<=A.length(); i+=3){
        for(int k=3; k<=B.length(); k+=3){
            if(A.substr(i-3,3)==B.substr(k-3,3)) dp[i][k]=dp[i-3][k-3]+1;
            else dp[i][k]=max(dp[i-3][k],dp[i][k-3]);
            
        }
    }
    cout<<dp[A.length()][B.length()];
}

๋Œ“๊ธ€