문제 출처 : www.acmicpc.net/problem/15663
문제 해석 : N개의 수 중에서 M개를 고르는데 중복 없이 결과를 출력해야한다. 이때 N은 중복된 수가 들어있다.
문제 풀이 : permutations과 set을 활용해서 문제를 풀 수 있다.
풀이 코드
from itertools import permutations
N, M = map(int, input().split())
num_list = list(map(int, input().split()))
num_list.sort()
answer = []
for candidate in list(permutations(num_list, M)):
answer.append(candidate)
answer = sorted(list(set(answer)))
for ans in answer:
for element in ans:
print(element, end = " ")
print()
author : donghak park
contact : donghark03@naver.com
## 문제의 저작권은 백준 알고리즘 사이트에 있습니다. 혹시 문제가 되는 부분이 있으면 연락 바랍니다.
'📊알고리즘, 문제풀이 > 📈문제풀이 (PS)' 카테고리의 다른 글
[알고리즘][Python] 백준 16953 A-->B 문제 풀이 (0) | 2021.02.01 |
---|---|
[알고리즘][Python] 백준 15666 N과 M (12) 문제 풀이 (0) | 2021.01.31 |
[알고리즘][Python] 백준 15657 N과 M (8) 문제 풀이 (0) | 2021.01.30 |
[알고리즘][Python] 백준 14938 서강그라운드 문제 풀이 (0) | 2021.01.30 |
[알고리즘][Python] 백준 13549 숨바꼭질 3 문제 풀이 (0) | 2021.01.29 |