본문 바로가기
기타/백준일지

[백준] 9251번 가장 긴 증가하는 수열

by 민지기il 2025. 2. 20.
#include <bits/stdc++.h>
#define fastio cin.tie(0)->sync_with_stdio(0)
using namespace std;

int dp [1001][1001];
string s1, s2;
int main(){
    fastio;
    cin>>s1>>s2;
    for(int i=1; i<=s1.length(); i++){
        for(int j=1; j<=s2.length(); j++){
            if(s1[i-1] == s2[j-1]){
                dp[i][j] = dp[i-1][j-1] +1;
            }
            else{
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    cout<<dp[s1.length()][s2.length()];
    return 0;
}

<참고>

https://ongveloper.tistory.com/36