알고리즘

[알고리즘] 백준 2631 - 줄세우기 (C++)

blueberrysoda 2025. 1. 12. 21:14

[문제 링크] : https://www.acmicpc.net/problem/2631

#include <iostream>
using namespace std;

int N, Maxi;
int Arr[201];
int DP[201];

int main(){
    cin >> N;
    for(int i=1; i<=N; i++){
        cin >> Arr[i];
    }

    for(int i=1; i<=N; i++){
        DP[i] = 1;
        for(int j=1; j<i; j++){
            if(Arr[j] < Arr[i] && DP[j] + 1> DP[i]){
                DP[i] = DP[j] + 1;
            }
        }

        Maxi = max(Maxi, DP[i]);
    }

    cout << N - Maxi << "\n";
    return 0;
}