|
์ฝ๋ ์์ฑํ๊ธฐ
n, m = map(int, input().split())
lst = []
def dfs():
if len(lst) == m:
print(' '.join(map(str, lst)))
return
for i in range(1, n+1):
if i not in lst:
lst.append(i)
# print(f"i={i}, lst={lst}")
dfs()
lst.pop()
dfs()
Python
๋ณต์ฌ
|
์ฝ๋ ์ค๋ช
ํ๊ธฐ
1.
lst: ์ฌ๊ทํจ์๋ฅผ ์ด์ฉํด m๊ฐ์ ์์ด์ ์ ์ฅํ ๋ฆฌ์คํธ
2.
๋ฆฌ์คํธ์ m๊ฐ์ ๊ฐ์ด ์ ์ฅ๋๋ฉด ์ถ๋ ฅํ๊ณ ๋ฆฌํด
3.
for๋ฌธ์ ํตํด 1๋ถํฐ n๊น์ง์ ์ซ์๋ค์ ๋ชจ๋ ํ์ธ
4.
๊ฐ ์ค๋ณต ํ์ธํ๊ธฐ
5.
์ค๋ณต์ด ์์ผ๋ฉด ๊ฐ์ ๋ฃ๋๋ค
6.
๋ค์ ์ซ์๋ฅผ ๋ฃ๊ธฐ ์ ์ m๊ฐ์ ์์ด์ด ๋ง๋ค์ด์ง๋ค๋ฉด ์ถ๋ ฅํ๊ธฐ ์ํด ์ฌ๊ท
7.
lst[1] โ lst[1,2]:์ถ๋ ฅ โ lst[1] โ lst[1.3]์ถ๋ ฅ โ lst[1] โ lst[1,4]
pop() pop()