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

[Python Algorithm] N๊ณผ M (2) BOJ #15650

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

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

 

15650๋ฒˆ: N๊ณผ M (2)

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

www.acmicpc.net

 

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

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

dfs()

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

 

๐Ÿ’ก ํ”ผ๋“œ๋ฐฑ
  • ๋ฐฑํŠธ๋ž˜ํ‚น ๊ฐœ๋…์„ ์•Œ๊ณ ์žˆ์œผ๋ฉด ์‰ฝ๊ฒŒ ํ’€ ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ์˜€๋‹ค.

๋Œ“๊ธ€