카테고리 없음
[Java] 백준 - 2529번: 부등호
C0MPAS
2024. 6. 27. 13:37
6월 27일(목) - 브루트 포스(2529번)
https://www.acmicpc.net/problem/2529
최초 생각 정리
문제점
풀이
(풀이출처 -> https://velog.io/@hyeokjinon/백준-2529-부등호-Java)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
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 || check(Character.getNumericValue(num.charAt(idx - 1)), j, arr[idx - 1]))
{
visited[j] = true;
dfs(num+j, idx+1);
visited[j] = false;
}
}
}
static boolean check(int a, int b, String str){
if(str.equals(">"))
{
if(a < b)
{
return false;
}
}
else if(str.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.println(list.get(list.size() - 1));
System.out.println(list.get(0));
}
}