diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index dc7e9ef82..b6791a3ca 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -20,6 +20,24 @@ } } ] + }, + { + "id": "eb395fb0544b127a", + "type": "tabs", + "children": [ + { + "id": "f9bf8e36633db0aa", + "type": "leaf", + "state": { + "type": "markdown", + "state": { + "file": "src/content/blog/boj-15666-N과-M-(12).md", + "mode": "source", + "source": false + } + } + } + ] } ], "direction": "vertical" @@ -85,7 +103,7 @@ "state": { "type": "backlink", "state": { - "file": "src/content/blog/boj-1699-제곱수의-합.md", + "file": "src/content/blog/boj-15666-N과-M-(12).md", "collapseAll": false, "extraContext": false, "sortOrder": "alphabetical", @@ -102,7 +120,7 @@ "state": { "type": "outgoing-link", "state": { - "file": "src/content/blog/boj-1699-제곱수의-합.md", + "file": "src/content/blog/boj-15666-N과-M-(12).md", "linksCollapsed": false, "unlinkedCollapsed": true } @@ -125,7 +143,7 @@ "state": { "type": "outline", "state": { - "file": "src/content/blog/boj-1699-제곱수의-합.md" + "file": "src/content/blog/boj-15666-N과-M-(12).md" } } } @@ -148,10 +166,11 @@ "table-editor-obsidian:Advanced Tables Toolbar": false } }, - "active": "b8e26a343e35175e", + "active": "f9bf8e36633db0aa", "lastOpenFiles": [ - "src/content/blog/boj-11725-트리의-부모-찾기.md", "src/content/blog/boj-1699-제곱수의-합.md", + "src/content/blog/boj-15666-N과-M-(12).md", + "src/content/blog/boj-11725-트리의-부모-찾기.md", "src/content/blog/computer-science-qna.md", "src/content/blog/boj-1026-보물.md", "src/content/blog/boj-15663-N과-M-(9).md", @@ -194,7 +213,6 @@ "src/assets/template/obsidian-template.md", "src/content/blog/ubuntu-partition.md", "src/content/blog/update-markdown-AST-node-url-value.md", - "src/content/blog/uninstall-wsl-completely-on-windows.md", - "src/content/blog/wooteco-2nd-thoughts.md" + "src/content/blog/uninstall-wsl-completely-on-windows.md" ] } \ No newline at end of file diff --git "a/src/content/blog/boj-15666-N\352\263\274-M-(12).md" "b/src/content/blog/boj-15666-N\352\263\274-M-(12).md" new file mode 100644 index 000000000..41e785520 --- /dev/null +++ "b/src/content/blog/boj-15666-N\352\263\274-M-(12).md" @@ -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))) + +```