7490-g5 풀이 보고 성공
This commit is contained in:
39
workbook_8708/gold/7490-g5.py
Normal file
39
workbook_8708/gold/7490-g5.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# 0 만들기
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from collections import deque
|
||||||
|
|
||||||
|
input = sys.stdin.readline
|
||||||
|
|
||||||
|
|
||||||
|
OPERATOR = [" ", "+", "-"] # 아스키 순서
|
||||||
|
|
||||||
|
def dfs(depth, n, exp):
|
||||||
|
if depth == n:
|
||||||
|
exp += str(depth)
|
||||||
|
if eval(exp.replace(" ", "")) == 0:
|
||||||
|
print(exp)
|
||||||
|
return
|
||||||
|
|
||||||
|
for op in OPERATOR:
|
||||||
|
dfs(depth+1, n, exp+str(depth)+op)
|
||||||
|
|
||||||
|
def solution():
|
||||||
|
t = int(input().rstrip())
|
||||||
|
|
||||||
|
for _ in range(t):
|
||||||
|
n = int(input().rstrip())
|
||||||
|
dfs(1, n, "")
|
||||||
|
print()
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
solution()
|
||||||
|
|
||||||
|
"""
|
||||||
|
걸린 시간: 11:18~
|
||||||
|
|
||||||
|
시간 복잡도:
|
||||||
|
|
||||||
|
해설:
|
||||||
|
"""
|
||||||
Reference in New Issue
Block a user