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-15663-N과-M-(9).md
- Loading branch information
Showing
2 changed files
with
89 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
|
@@ -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", | ||
|
@@ -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 | ||
} | ||
|
@@ -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" | ||
} | ||
} | ||
} | ||
|
@@ -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", | ||
|
@@ -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]", | ||
|
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,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))) | ||
|
||
``` |