Skip to content

Commit

Permalink
2024-04-27 15:00:15
Browse files Browse the repository at this point in the history
Affected files:
.obsidian/workspace.json
src/content/blog/boj-15663-N과-M-(9).md
  • Loading branch information
gyunseo committed Apr 27, 2024
1 parent a2b6c49 commit b9d912c
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 6 deletions.
30 changes: 24 additions & 6 deletions .obsidian/workspace.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@
{
"id": "e86c6645d916ff37",
"type": "tabs",
"children": [
{
"id": "5a6261ed362b5274",
"type": "leaf",
"state": {
"type": "markdown",
"state": {
"file": "src/content/blog/boj-15663-N과-M-(9).md",
"mode": "source",
"source": false
}
}
}
]
},
{
"id": "e73fc0b6ffcb5498",
"type": "tabs",
"children": [
{
"id": "544848df0440480a",
Expand Down Expand Up @@ -85,7 +103,7 @@
"state": {
"type": "backlink",
"state": {
"file": "src/content/blog/boj-15664-N과-M-(10).md",
"file": "src/content/blog/boj-15663-N과-M-(9).md",
"collapseAll": false,
"extraContext": false,
"sortOrder": "alphabetical",
Expand All @@ -102,7 +120,7 @@
"state": {
"type": "outgoing-link",
"state": {
"file": "src/content/blog/boj-15664-N과-M-(10).md",
"file": "src/content/blog/boj-15663-N과-M-(9).md",
"linksCollapsed": false,
"unlinkedCollapsed": true
}
Expand All @@ -125,7 +143,7 @@
"state": {
"type": "outline",
"state": {
"file": "src/content/blog/boj-15664-N과-M-(10).md"
"file": "src/content/blog/boj-15663-N과-M-(9).md"
}
}
}
Expand All @@ -148,10 +166,11 @@
"table-editor-obsidian:Advanced Tables Toolbar": false
}
},
"active": "544848df0440480a",
"active": "5a6261ed362b5274",
"lastOpenFiles": [
"src/content/blog/boj-1935-후위-표기식2.md",
"src/content/blog/boj-15664-N과-M-(10).md",
"src/content/blog/boj-15663-N과-M-(9).md",
"src/content/blog/boj-1935-후위-표기식2.md",
"src/content/blog/boj-10819-차이를-최대로.md",
"src/content/blog/boj-1026-보물.md",
"src/content/blog/programmers-보호소에서-중성화한-동물.md",
Expand All @@ -177,7 +196,6 @@
"src/content/blog/wooteco-1st-thoughts.md",
"src/content/blog/create-ssh-key-for-github.md",
"src/content/blog/bfs-algorithm-technique.md",
"src/content/blog/go-study.md",
"dist/assets/[email protected]",
"dist/assets/forrest-gump-quote.webp.jpg",
"dist/_astro/[email protected]",
Expand Down
65 changes: 65 additions & 0 deletions src/content/blog/boj-15663-N과-M-(9).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
author: Gyunseo Lee
title: "BOJ 백준 15663: N과 M (9)"
pubDatetime: 2024-04-27T14:53:00+09:00
modDatetime: 2024-04-27T14:53:00+09:00
featured: false
draft: false
tags:
- PS
- Algorithms
- BOJ
- Backtracking
- 실랜디
description: "백준 15663: N과 M (9) 풀이 과정"
ogImage: ""
---

## Table of contents

## 들어가며

[BOJ 백준 15664: N과 M (10)](<boj-15664-N과-M-(10).md>)풀이와 상당히 비슷합니다.
이번 문제는 수열의 제한 조건에 단조 증가 수열이 아니라서 일종의 permutation들을 구하는 것이라고 볼 수 있습니다.

## AC 받은 Python 코드

```python
import sys

input = sys.stdin.readline


def permutation(cur_len):
# base condition 1
if cur_len == M:
ansSet.add(tuple(seq))
return

for i in range(lenNums):
if isUsed[i]:
continue
isUsed[i] = True
seq.append(nums[i])
permutation(cur_len + 1)
isUsed[i] = False
seq.pop()


if __name__ == "__main__":
N, M = map(int, input().rstrip().split())
nums = [*sorted(map(int, input().rstrip().split()))]
lenNums = len(nums)
isUsed = [False for _ in range(lenNums)]
seq = []
ansSet = set()
for i in range(lenNums):
isUsed[i] = True
seq.append(nums[i])
permutation(1)
isUsed[i] = False
seq.pop()
for ans in sorted(ansSet):
print(" ".join(map(str, ans)))

```

0 comments on commit b9d912c

Please sign in to comment.