practivceAlgorithm/백준
[백준][Python] 2529 부등호
findTheValue
2021. 7. 16. 23:06
문자열에 str처리해서 더하면 되는것을.. list만드는 병에 걸려서..
문제 보자마자 중복없는 순열에 DFS넣을때마다 부등호 바꿔주는 조건. N과M(12)까지 다 풀었다면 아이디어 자체는 어렵지 않다.
n = int(input())
inequality = input().split()
check = [False] * 10
max, min = "", ""
def possible(i, j, k):
if k == '<':
return i < j
if k == '>':
return i > j
return True
def DFS(depth, s):
global max, min
if depth == n + 1:
if not len(min):
min = s
else:
max = s
return
for i in range(10):
if not check[i]:
if depth == 0 or possible(s[-1], str(i), inequality[depth - 1]):
check[i] = True
DFS(depth + 1, s + str(i))
check[i] = False
DFS(0, "")
print(max)
print(min)