반응형
https://www.acmicpc.net/problem/15655
15655번: N과 M (6)
N개의 자연수와 자연수 M이 주어졌을 때, 아래 조건을 만족하는 길이가 M인 수열을 모두 구하는 프로그램을 작성하시오. N개의 자연수는 모두 다른 수이다. N개의 자연수 중에서 M개를 고른 수열
www.acmicpc.net
import sys
input=sys.stdin.readline
n,m = list(map(int,input().split()))
nums= [int(x) for x in input().split()]
nums.sort()
s = []
def dfs(st):
if len(s)==m:
print(' '.join(map(str,s)))
return
for i in range(st, len(nums)):
if nums[i] not in s:
s.append(nums[i])
dfs(i+1)
s.pop()
dfs(0) # 기준이 인덱스가 됨
반응형
'프로그래밍 > 알고리즘 & 자료구조' 카테고리의 다른 글
백준 10810 : 공넣기 with 파이썬 (0) | 2024.01.23 |
---|---|
백준 1966 : 프린터 큐 with 파이썬 (0) | 2024.01.22 |
백준 15649 : N과 M (1) with 파이썬 (0) | 2024.01.20 |
백준 2667번 : 단지번호 붙이기 with 파이썬 (0) | 2024.01.20 |
[프로그래머스] 소수 찾기 with 파이썬 (0) | 2023.12.29 |
댓글