티스토리 뷰
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);
}
}
가장 긴 증가하는 부분 수열과 비슷한 문제.
'Algorithm > Baekjoon Online Judge' 카테고리의 다른 글
| 2609번 '최대공약수와 최소공배수' (0) | 2018.07.31 |
|---|---|
| 1912번 '연속합' (0) | 2018.07.30 |
| 11055번 '가장 큰 증가 부분 수열' (0) | 2018.07.29 |
| 11053번 '가장 긴 증가하는 부분 수열' (0) | 2018.07.29 |
| 2748번 '피보나치 수 2' (0) | 2018.04.29 |
댓글
