코딩테스트 대비/BOJ
[Baekjoon/Python] 15654번: N과 M (5) - 효과는 굉장했다!
bluetag_boy
2022. 3. 14. 00:13
반응형
15654번: N과 M (5)
N개의 자연수와 자연수 M이 주어졌을 때, 아래 조건을 만족하는 길이가 M인 수열을 모두 구하는 프로그램을 작성하시오. N개의 자연수는 모두 다른 수이다. N개의 자연수 중에서 M개를 고른 수열
www.acmicpc.net
알고리즘 분류
- 백트래킹
SOLUTION
import sys
from itertools import permutations
N, M = map(int, sys.stdin.readline().split())
num_list = list(map(int, sys.stdin.readline().split()))
permu = list(permutations(num_list, M)) #permutations()함수 이용
permu.sort()
for i in permu:
print(*i) # *를 통해 unpacking