PS

BOJ 11722 : 가장 긴 감소하는 부분 수열

lickelon 2025. 1. 2. 01:14

코드

#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()

#define INF 0x7FFFFFFF

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll, ll>;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n;
    cin >> n;
    vector<int> arr(n), dp(n, 0);
    for(auto &e : arr) cin >> e;

    for(int i = 0; i < n; i++) {
        int M = 0;
        for(int j = 0; j < i; j++) {
            if(arr[j] > arr[i]) M = max(M, dp[j]);
        }
        dp[i] = M+1;
    }
    int ans = 0;
    for(auto e : dp) ans = max(ans, e);
    cout << ans;

    return 0;
}

풀이

LIS와 같다.

728x90

'PS' 카테고리의 다른 글

BOJ 10799 : 쇠막대기  (0) 2025.01.03
BOJ 28136 : 원, 탁!  (0) 2025.01.02
BOJ 3986 : 좋은 단어  (0) 2024.12.31
BOJ 10816 : 숫자 카드 2  (0) 2024.12.30
BOJ 33049 : 마작에서 가장 어려운 것  (0) 2024.12.30