728x90
www.acmicpc.net/workbook/view/2052
백트래킹을 연습하기 위해 4번까지 풀었다.
15649
n, m = map(int, input().split())
visited = [0] * (n + 1)
def asdf(index=0, arr=[], key=m, end=n):
if index == key:
print(' '.join(map(str, arr)))
else:
for i in range(1,end+1):
if visited[i] == 0:
visited[i] = 1
asdf(index + 1, arr + [i])
visited[i] = 0
asdf()
15650
n, m = map(int, input().split())
def asdf(index=0, start=1, end=n, key=m, arr=[]):
if index == key:
print(' '.join(map(str, arr)))
else:
for i in range(start, end+1):
asdf(index=index+1, start=i+1, arr= arr+[i])
asdf()
15651
n, m = map(int, input().split())
def asdf(index=0, end=n, key=m, arr=[]):
if index == key:
print(' '.join(map(str, arr)))
else:
for i in range(1, end+1):
asdf(index=index+1, arr= arr+[i])
asdf()
15652
n, m = map(int, input().split())
def asdf(index=0, start=1,end=n, key=m, arr=[]):
if index == key:
print(' '.join(map(str, arr)))
else:
for i in range(start, end+1):
asdf(index=index+1, start=i , arr= arr+[i])
asdf()
'STUDY > Algorithm' 카테고리의 다른 글
[백준] 6603 로또 (0) | 2021.03.04 |
---|---|
[백준] 2583 영역구하기 (0) | 2021.03.04 |
[백준] 2798 블랙잭 (0) | 2021.03.04 |
[백준] 2309 일곱 난쟁이 (0) | 2021.03.04 |
[백준] 7569 토마토 (2) | 2021.03.02 |