*문제 출처는 백준에 있습니다.
문제 제목: N과 M (6) / 15655번 (실버 3단계)
문제 사이트: https://www.acmicpc.net/problem/15655
문제 설명

나의 풀이
def dfs(cu, n, m, sequence, visited, start):
if len(cu) == m:
print(' '.join(cu))
return
for i in range(start, n):
if not visited[i]:
cu.append(str(sequence[i]))
visited[i] = True
dfs(cu, n, m, sequence, visited, i)
visited[i] = False
cu.pop()
def main():
n, m = map(int, input().split())
sequence = sorted(list(map(int, input().split())))
visited = [False] * n
dfs([], n, m, sequence, visited, 0)
main()

※ 알아야 할 것
백트래킹 문제입니다!
소요 시간: 3:30
사유: 자주 풀다보니 감이 잡혔습니다.
'Coding Test > 백준-Python' 카테고리의 다른 글
| 백준 / 토마토 / 7569번 / Python (0) | 2025.03.10 |
|---|---|
| 백준 / N과 M (7) / 15656번 / Python (0) | 2025.03.09 |
| 백준 / N과 M (8) / 15657번 / Python (0) | 2025.03.06 |
| 백준 / 부분수열의 합 / 1182번 / Python (0) | 2025.03.04 |
| 백준 / IQ Test / 1111번 / Python (0) | 2025.03.03 |