티스토리 뷰

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

class Main {
static int d[];
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int count = Integer.parseInt(in.readLine());
String input[] = in.readLine().split(" ");
int[] sequence = new int[count];
for(int i=0; i<count; ++i) {
sequence[i] = Integer.parseInt(input[i]);
}
d = new int[count];
for(int i=0; i<count; ++i) {
d[i] = 1;
for(int j=0; j<i; ++j) {
if(sequence[j] > sequence[i] && d[j] + 1 > d[i]) {
d[i] = d[j] + 1;
}
}
}
int result = 0;
for(int element: d) {
if(element > result)
result = element;
}
System.out.println(result);
}
}


가장 긴 증가하는 부분 수열과 비슷한 문제.

댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2026/01   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함