2021-02-07
문제 : https://www.acmicpc.net/problem/15655
15655번: N과 M (6)
N개의 자연수와 자연수 M이 주어졌을 때, 아래 조건을 만족하는 길이가 M인 수열을 모두 구하는 프로그램을 작성하시오. N개의 자연수는 모두 다른 수이다. N개의 자연수 중에서 M개를 고른 수열
www.acmicpc.net
1. N개의 자연수 중에서 M개를 고른 수열
2. 고른 수열은 오름차순이어야 한다.
3. N개의 자연수는 모두 다른 수
2번 조건때문에 처음에 받은 입력 값을 오름차순으로 정렬함
combinations 사용해서 풀이함
[소스코드]
https://github.com/jisun1125/algorithm-problem-solving/blob/main/baekjoon/no_15655.py
jisun1125/algorithm-problem-solving
Algorithms. Contribute to jisun1125/algorithm-problem-solving development by creating an account on GitHub.
github.com
from itertools import combinations
n, m = map(int, input().split())
k = sorted(list(map(int, input().split())))
C = combinations(k, m)
for c in C:
for i in c:
print(i, end=' ')
print('')
'PS > 백준' 카테고리의 다른 글
[백준/Python(파이썬)] 15657 N과 M (8) (0) | 2021.02.14 |
---|---|
[백준/Python(파이썬)] 15656 N과 M (7) (0) | 2021.02.14 |
[백준/Python(파이썬)] 15654 N과 M (5) (0) | 2021.02.14 |
[백준/Python(파이썬)] 15652 N과 M (4) (0) | 2021.02.14 |
[백준/Python(파이썬)] 15651 N과 M (3) (0) | 2021.02.14 |