카테고리 없음

백준 11053. 가장 긴 증가하는 부분 수열

tose33 2021. 3. 2. 19:28

다시 푼 문제.

www.acmicpc.net/problem/11053

 

11053번: 가장 긴 증가하는 부분 수열

수열 A가 주어졌을 때, 가장 긴 증가하는 부분 수열을 구하는 프로그램을 작성하시오. 예를 들어, 수열 A = {10, 20, 10, 30, 20, 50} 인 경우에 가장 긴 증가하는 부분 수열은 A = {10, 20, 10, 30, 20, 50} 이

www.acmicpc.net

 

이전 글 : tose33.tistory.com/18

 

 

#include <iostream>
using namespace std;
#include <algorithm>

int d[1001];
int a[1001];

int main() {
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];

    d[1] = 1;

    pair<int, int> memo = make_pair(0,0);
    for(int i = 2; i <= n; i++) {
        int memo = 0; // memorize the biggest value
        for(int j = 1; j < i; j++) {
            if(a[j] < a[i] && d[j] > memo) {
                memo = d[j];
            }
        }
        d[i] = memo + 1;
    }

    cout << *max_element(d, d+n+1);

}