ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ 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
- ๋ฐ๋
- ์คํ
- ์๊ฐ๊ต์ฒด
- dfs
- MongoDB
- ์๋ฐ
- BOJ
- dp
- ๋งฅ๋ถํ๋ก
- ํ
- baekjoon
- BFS
- ํด์๋งต
- ๋ชฝ๊ณ ๋๋น
- ๋ธ๋ฃจํธํฌ์ค
- ์ด๋ถํ์
- ๋งฅ๋ถ
- ๋ฐฑ์ค
- ballet
- Macbook pro 2012 mid 13
- ๋ถํ ์ ๋ณต
- ํ๋ก์ด๋์์ฌ
- AWS
- Golang
- go
- java
- ์๊ณ ๋ฆฌ์ฆ
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- python3
- Algorithm
- Total
- Today
- Yesterday