Algorithm/Baekjoon Online Judge

11722번 '가장 긴 감소하는 부분 수열'

할루루 2018. 7. 29. 21:24
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);
}
}


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