https://www.acmicpc.net/problem/2992
나의 코드
import sys
sys.setrecursionlimit(10**6)
def check():
global mid_res
if len(mid_res) == n and int(mid_res) > int(x): # 글자 수가 n와 같고 만들어진 숫자가 x보다 크다면
result.add(int(mid_res)) # result에 추가
return
for i in range(n):
if visited[i] == 0:
mid_res += x[i]
visited[i] = 1
check()
mid_res = mid_res[:-1]
visited[i] = 0
x = input()
n = len(x) # x 길이
visited = [0]*n # 구성을 같게 하기 위한 방문리스트 설정
result = set()
mid_res = ''
check()
result = list(result)
result.sort()
if len(result) == 0:
print(0)
else:
print(result[0])
결과

숫자판 점프와 같은 방식으로 풀면 된다. 구성을 같게 하기 위해 visited만 추가하면 간단하게 풀 수 있는 문제였다!
'스터디 1일 1커밋' 카테고리의 다른 글
| 240617 [BOJ/백준] 10994. 별찍기-19 (0) | 2024.06.17 |
|---|---|
| 240613 [프로그래머스] 42842. 카펫 (1) | 2024.06.13 |
| 240611 [BOJ/백준] 1021. 회전하는 큐 (0) | 2024.06.11 |
| 240611 [BOJ/백준] 2210. 숫자판 점프 (0) | 2024.06.11 |
| 240610 [BOJ/백준] 1912. 연속합 (0) | 2024.06.10 |