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

https://www.acmicpc.net/problem/11053

 

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

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

www.acmicpc.net

 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        int[] arr = new int[N];
        StringTokenizer stk = new StringTokenizer(br.readLine());
        for(int i=0; i<N; i++){
            arr[i] = Integer.parseInt(stk.nextToken());
        }
        int[] countArr = new int[N];

        int answer = Integer.MIN_VALUE;

        countArr[0] = 1;

        for(int i=1; i<N; i++){
            countArr[i] = 1;
            for(int j=0; j<i; j++){
                if(arr[j]<arr[i] && countArr[j]>=countArr[i]){
                    countArr[i] = countArr[j]+1;
                }
            }
        }

        for(int x : countArr){
            answer = Math.max(answer, x);
        }

        System.out.print(answer);

    }
}

'Solved > BOJ' 카테고리의 다른 글

[백준 9663] N-Queen  (0) 2023.05.05
[백준 17136] 색종이 붙이기  (0) 2023.05.05
[백준 1912] 연속합  (0) 2023.05.02
[백준 10816] 숫자 카드 2  (0) 2023.04.30
[백준 1620] 나는야 포켓몬 마스터 이다솜  (0) 2023.04.29