Algorithm/백준
[Python] 백준 15663번: N과 M (9)
hanbikan
2021. 7. 27. 12:25
https://www.acmicpc.net/problem/15663
15663번: N과 M (9)
한 줄에 하나씩 문제의 조건을 만족하는 수열을 출력한다. 중복되는 수열을 여러 번 출력하면 안되며, 각 수열은 공백으로 구분해서 출력해야 한다. 수열은 사전 순으로 증가하는 순서로 출력해
www.acmicpc.net
import sys
import itertools
input = sys.stdin.readline
if __name__ == '__main__':
N, M = map(int, input().split())
nums = map(int, input().split())
for cur in sorted(list(set(itertools.permutations(nums, M)))):
print(*cur)
입력받은 숫자들을 permutations() 해주고, 중복수열이 있으면 안 되므로 set()로 중복을 제거해주며, 마지막으로 정렬시켜주면 된다.