[BaekJoon] ๋ฐฑ์ค€ 15650๋ฒˆ : N๊ณผ M (2)

Updated:

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


ํŒŒ์ด์ฌ์˜ combination ๊ณผ ์ถœ๋ ฅํ•˜๋Š” ๋ฐฉ์‹์„ ์•Œ๋ฉด ํ’€ ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ์ด๋‹ค..

์—ญ์‹œ ์˜ค๋žœ๋งŒ์— ๋ฌธ์ œ๋ฅผ ํ’€์–ด์„œ ๊ทธ๋Ÿฐ์ง€ combination ์‚ฌ์šฉํ•˜๋Š” ๋ฒ•๋„ ์žŠ๊ณ  ์žˆ์—ˆ๋‹ค..

์ฃผ์–ด์ง„ ์กฐ๊ฑด๋Œ€๋กœ ์ˆ˜์—ด์„ ๋งŒ๋“  ๋’ค ์ถœ๋ ฅ ์กฐ๊ฑด์— ๋งž๊ฒŒ ์ถœ๋ ฅ์„ ํ•˜๋ฉด ๋œ๋‹ค.


import sys
from itertools import combinations

n, m = map(int, sys.stdin.readline().rsplit())
data = [i for i in range(1, n + 1)]
output = list(combinations(data, m))

for i in output:
	for val in i:
		print(val, end=" ")
	print()



Categories:

Updated:

Leave a comment