1,2,3 더하기(2) 12101
def dfs(s):
global result
visited[s] = True
if sum(result) == n:
total_result.append(result[:])
return
for next in range(1, 4):
if sum(result) < n:
result.append(next)
dfs(next)
result.pop(-1)
n, k = map(int, input().split())
visited = [False]*(4)
result = []
total_result = []
dfs(0)
if n == 1 and k == 1:
print(1)
elif len(total_result) > k-1:
print("+".join(map(str, total_result[k-1])))
else:
print(-1)
참고자료 codeplus