코딩테스트
[백준] 15649 | N과 M (1) [파이썬/python]
사용할수없는닉네임이왜이렇게많지ㅠㅠ
2025. 3. 21. 19:35
728x90
문제
link: https://www.acmicpc.net/problem/15649
1부터 N까지의 자연수 중 M개를 중복 없이 골라 나열하는 법을 모두 출력하는 문제이다.
접근
파이썬의 itertools 라이브러리를 활용하면 쉽게 계산할 수 있다. permutations()로 수열을 모두 구한 후 for문으로 순회하며 출력해주었다.
코드
import sys
from itertools import permutations
input = sys.stdin.readline
N, M = map(int, input().split())
l = [x for x in range(1, N+1)]
P = permutations(l, M)
for p in P:
print(' '.join(map(str, p)))
728x90