문제 링크: https://www.acmicpc.net/problem/2529
백준 알고리즘 기초 2/2 530에서 6번째 - 2529번 부등호를 풀어보았다.
풀이: https://great-park.tistory.com/38 를 참고했다.
C++
Python
def check(a,b,c):
if c=='<': return a<b
else: return a>b
def res(depth,s):
global maxs,mins
if depth==k+1:
if len(mins)==0: mins=s
else: maxs=s
return
for i in range(10):
if not visit[i]:
if depth==0 or check(s[-1],str(i),arr[depth-1]):
visit[i]=True
res(depth+1,s+str(i))
visit[i]=False
k=int(input())
arr=list(input().split())
visit=[0]*10
maxs=""
mins=""
res(0,"")
print(maxs)
print(mins)
Java
'코테용 문제풀이 > 백준' 카테고리의 다른 글
집합 풀이 (0) | 2023.02.02 |
---|---|
맞춰봐 풀이 (0) | 2023.02.02 |
링크와 스타트 풀이 (0) | 2023.01.29 |
스타트와 링크 풀이 (0) | 2023.01.29 |
퇴사 풀이 (0) | 2023.01.29 |