https://www.acmicpc.net/problem/2529
2529번: 부등호
여러분은 제시된 부등호 관계를 만족하는 k+1 자리의 최대, 최소 정수를 첫째 줄과 둘째 줄에 각각 출력해야 한다. 단 아래 예(1)과 같이 첫 자리가 0인 경우도 정수에 포함되어야 한다. 모든 입력에 답은 항상 존재하며 출력 정수는 하나의 문자열이 되도록 해야 한다.
www.acmicpc.net
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | def recur(idx): if len(tmp) == k+1: result.append(tmp[:]) return for i in range(10): if idx == -1 and candi[i]: tmp.append(i) candi[i] -= 1 recur(idx + 1) tmp.pop() candi[i] += 1 else: if a[idx] == '<': if tmp[idx] < i and candi[i]: tmp.append(i) candi[i] -= 1 recur(idx+1) tmp.pop() candi[i] += 1 elif a[idx] == '>': if tmp[idx] > i and candi[i]: tmp.append(i) candi[i] -= 1 recur(idx+1) tmp.pop() candi[i] += 1 k = int(input()) a = input().split() candi = [1]*10 tmp = [] result = [] recur(-1) print(''.join(map(str, result[-1]))) print(''.join(map(str, result[0]))) | cs |
728x90
반응형
'Problem Solving > BOJ' 카테고리의 다른 글
[Python]14889. 스타트와 링크 (0) | 2019.04.22 |
---|---|
[Python]17143. 낚시왕 (0) | 2019.04.18 |
[Python]17127. 벚꽃이 정보섬에 피어난 이유 (0) | 2019.04.14 |
[Python]15559. 내 선물을 받아줘 (0) | 2019.04.14 |
[Python]13335. 트럭 (0) | 2019.04.13 |
댓글