๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
4๏ธโƒฃ Python/Problem Solving

[Python Algorithm] N๊ณผ M (3) BOJ #15651

by seolhee2750 2022. 2. 15.
๋ฌธ์ œ

https://www.acmicpc.net/problem/15651

 

15651๋ฒˆ: N๊ณผ M (3)

ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ๋ฌธ์ œ์˜ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋Š” ์ˆ˜์—ด์„ ์ถœ๋ ฅํ•œ๋‹ค. ์ค‘๋ณต๋˜๋Š” ์ˆ˜์—ด์„ ์—ฌ๋Ÿฌ ๋ฒˆ ์ถœ๋ ฅํ•˜๋ฉด ์•ˆ๋˜๋ฉฐ, ๊ฐ ์ˆ˜์—ด์€ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„ํ•ด์„œ ์ถœ๋ ฅํ•ด์•ผ ํ•œ๋‹ค. ์ˆ˜์—ด์€ ์‚ฌ์ „ ์ˆœ์œผ๋กœ ์ฆ๊ฐ€ํ•˜๋Š” ์ˆœ์„œ๋กœ ์ถœ๋ ฅํ•ด

www.acmicpc.net

 

๋‚ด ๋ฌธ์ œ ํ’€์ด
n, m = map(int, input().split())
tmp = []
result = []

def dfs():
    if len(tmp) == m:
        print(' '.join(map(str, tmp)))
        return
    for i in range(1, n+1):
        tmp.append(i)
        dfs()
        tmp.pop()

dfs()

๐Ÿ‘‰ ๋ฐฑํŠธ๋ž˜ํ‚น ๋ฌธ์ œ ! (https://seolhee2750.tistory.com/189 ์ฐธ๊ณ )

 

๐Ÿ’ก ํ”ผ๋“œ๋ฐฑ
  • ๋ฐฑํŠธ๋ž˜ํ‚น ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ž˜ ์•Œ๊ณ  ์žˆ์œผ๋ฉด ์‰ฝ๊ฒŒ ํ’€ ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ !

๋Œ“๊ธ€