728x90
SMALL

재귀함수 어렵다...
import java.util.*; import java.io.*; class Main{ static int[] arr; static int[] d; public static void main(String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); arr = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); d = new int[arr.length]; for(int i = 0 ; i<arr.length ; i++){ L(i); } int max = d[0]; for(int i=1 ; i<d.length ; i++){ max = Math.max(max, d[i]); } System.out.println(max); } public static int L(int n){ if(d[n]==0){ d[n]=1; for(int i = n-1 ; i>=0 ; i--){ if(arr[i]<arr[n]) d[n] = Math.max(d[n], L(i)+1); } } return d[n]; } }
728x90
LIST
'Coding test > Baekjoon' 카테고리의 다른 글
[백준][JAVA] 26008번: 해시 해킹 (0) | 2023.08.12 |
---|---|
[백준][JAVA] 10818번: 최소, 최대 (0) | 2023.08.09 |
[백준][JAVA] 1021번: 회전하는 큐 (0) | 2023.08.09 |
[백준][JAVA] 2193번: 이친수 (0) | 2023.07.31 |
[백준][JAVA] 25556번: 포스택 (0) | 2023.02.14 |