[DP] [백준 / 11053] 실버 1 - 가장 긴 증가하는 부분 수열
(java/자바)

package B_DP;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class boj_11053 {
public static void main(String[] args) throws IOException {
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(r.readLine());
int[] arr = Arrays.stream(r.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
int[] dp = new int[N];
// dp 배열 초기화
Arrays.fill(dp, 1); // 모든 위치에서의 길이는 최소 1
// LIS 알고리즘 구현
for (int i = 1; i < N; i++) {
for (int j = 0; j < i; j++) {
if (arr[j] < arr[i]) {
dp[i] = Math.max(dp[i], dp[j] + 1);
}
}
}
// dp 배열에서 최대값 찾기
int max = Arrays.stream(dp).max().getAsInt();
System.out.println(max);
}
}