https://www.acmicpc.net/problem/2529
🌕 최종코드
import java.io.*;
import java.util.*;
public class Main {
static int n;
static boolean[] visited;
static String[] arr;
static List<String> list = new ArrayList<>();
static void dfs(String num, int idx) {
if(idx == n+1) {
list.add(num);
return;
}
for(int j = 0 ; j < 10; j++) {
// 사용한 숫자인지 체크
if(visited[j]) {
continue;
}
if(idx == 0 || ckeck(Character.getNumericValue(num.charAt(idx - 1)), j , arr[idx-1])) {
visited[j] = true;
dfs(num+j, idx+1);
visited[j] = false;
}
}
}
static boolean ckeck(int a, int b, String c) {
if (c.equals(">")) {
if(a < b) return false;
} else if (c.equals("<")){
if(a > b) return false;
}
return true;
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt(br.readLine());
arr = br.readLine().split(" ");
visited = new boolean[10];
dfs("",0);
//최대값
System.out.print(list.get(list.size() - 1) + "\n");
//최소값
System.out.print(list.get(0));
}
}
'항해' 카테고리의 다른 글
[DAY51] 99클럽 코딩테스트 JAVA 백준 치킨 배달 15686번 (0) | 2025.02.07 |
---|---|
[DAY50] 99클럽 코딩테스트 JAVA 백준 오목 2615번 (0) | 2025.02.06 |
[DAY48] 99클럽 코딩테스트 JAVA 백준 숫자 정사각형 1051번 (0) | 2025.02.04 |
[DAY47] 99클럽 코딩테스트 JAVA 백준 빙산 2573번 (0) | 2025.02.03 |
[DAY46] 99클럽 코딩테스트 JAVA 백준 빙산 2573번 (1) | 2025.01.24 |