ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
10974๋ฒ: ๋ชจ๋ ์์ด
N์ด ์ฃผ์ด์ก์ ๋, 1๋ถํฐ N๊น์ง์ ์๋ก ์ด๋ฃจ์ด์ง ์์ด์ ์ฌ์ ์์ผ๋ก ์ถ๋ ฅํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค.
www.acmicpc.net
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/10974
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var n int
fmt.Fscanln(reader, &n)
numbers := []int{}
for i := 0; i < n; i++ {
numbers = append(numbers, i+1)
}
permutations := getPermutations(numbers)
for i := 0; i < len(permutations); i++ {
permutationStr := fmt.Sprintf("%v", permutations[i])
fmt.Fprintln(writer, permutationStr[1:len(permutationStr)-1])
}
}
func getPermutations(elements []int) [][]int {
permutations := [][]int{}
if len(elements) == 1 {
permutations = [][]int{elements}
return permutations
}
for i := range elements {
el := append([]int(nil), elements...)
for _, perm := range getPermutations(append(el[0:i], el[i+1:]...)) {
permutations = append(permutations, append([]int{elements[i]}, perm...))
}
}
return permutations
}
๐จ Python3
# https://www.acmicpc.net/problem/10974
import sys
from itertools import permutations
if __name__ == "__main__":
n = int(sys.stdin.readline())
numbers = list(range(1, n+1))
for i in permutations(numbers):
for j in range(0, n):
print("{} ".format(i[j]), end='')
print()
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 11055๋ฒ / ๊ฐ์ฅ ํฐ ์ฆ๊ฐํ๋ ๋ถ๋ถ ์์ด [Go][Python3] (0) | 2021.03.31 |
---|---|
BOJ / 11722๋ฒ / ๊ฐ์ฅ ๊ธด ๊ฐ์ํ๋ ๋ถ๋ถ ์์ด [Go][Python3] (0) | 2021.03.30 |
BOJ / 2960๋ฒ / ์๋ผํ ์คํ ๋ค์ค์ ์ฒด [Go][Python3] (1) | 2021.03.28 |
BOJ / 1057๋ฒ / ํ ๋๋จผํธ [Go][Python3] (0) | 2021.03.27 |
BOJ / 11048๋ฒ / ์ด๋ํ๊ธฐ [Go][Python3] (0) | 2021.03.26 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- go
- ๋ถํ ์ ๋ณต
- ballet
- ์คํ
- Algorithm
- ๋งฅ๋ถ
- ๋ธ๋ฃจํธํฌ์ค
- ๋ฐ๋
- ๋ฐฑ์ค
- ํด์๋งต
- Macbook pro 2012 mid 13
- java
- AWS
- ๋งฅ๋ถํ๋ก
- dp
- ํ
- ์ด๋ถํ์
- ์๊ฐ๊ต์ฒด
- ๋ชฝ๊ณ ๋๋น
- baekjoon
- ์๋ฐ
- Golang
- BOJ
- ํ๋ก์ด๋์์ฌ
- BFS
- ์๊ณ ๋ฆฌ์ฆ
- python3
- MongoDB
- dfs
- Total
- Today
- Yesterday