forked from satnaing/astro-paper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Affected files: .obsidian/workspace.json src/content/blog/boj-15666-N과-M-(12).md
- Loading branch information
Showing
2 changed files
with
86 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
--- | ||
author: Gyunseo Lee | ||
title: "BOJ 백준 15666: N과 M (12)" | ||
pubDatetime: 2024-05-03T20:28:00+09:00 | ||
modDatetime: 2024-05-03T20:28:00+09:00 | ||
featured: false | ||
draft: false | ||
tags: | ||
- PS | ||
- Algorithms | ||
- BOJ | ||
- DFS | ||
- Backtracking | ||
- 실랜디 | ||
description: "\b백준 15666: N과 M (12) 풀이 과정" | ||
ogImage: "" | ||
--- | ||
|
||
## Table of contents | ||
|
||
## 들어가며 | ||
|
||
이 문제는 전형적인 N과 M 시리즈 문제입니다. | ||
문제의 조건을 잘 읽고, DFS와 Backtracking으로 구현하면 돼요... | ||
|
||
## AC 받은 Python 코드 | ||
|
||
```python | ||
import sys | ||
|
||
input = sys.stdin.readline | ||
|
||
|
||
def dfs(cur_len, cur_idx): | ||
# base condition 1 | ||
if cur_len == M: | ||
setSeqs.add(tuple(seq)) | ||
return | ||
|
||
for i in range(cur_idx, lenNums): | ||
seq.append(nums[i]) | ||
dfs(cur_len + 1, i) | ||
seq.pop() | ||
|
||
|
||
if __name__ == "__main__": | ||
N, M = map(int, input().rstrip().split()) | ||
nums = [*sorted(map(int, input().rstrip().split()))] | ||
seq = [] | ||
lenNums = len(nums) | ||
setSeqs = set() | ||
# print(nums) | ||
for i in range(lenNums): | ||
seq.append(nums[i]) | ||
dfs(1, i) | ||
seq.pop() | ||
|
||
for s in sorted(setSeqs): | ||
print(" ".join(map(str, s))) | ||
|
||
``` |