ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
var n, m int
reader := bufio.NewReader(os.Stdin)
fmt.Fscanln(reader, &n, &m)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var visited = make([]bool, n+1)
var result = make([]int, m+1)
sequence(writer, visited, result, 0, n, m)
}
func sequence(writer *bufio.Writer, visited []bool, result []int, index, n, m int) {
if index == m { // if result array is full
for i := 0; i < m; i++ {
fmt.Fprintf(writer, "%d ", result[i])
}
fmt.Fprint(writer, "\n")
return
}
for i := 1; i < n+1; i++ {
if visited[i] == true {
continue
}
result[index] = i
visited[i] = true
sequence(writer, visited, result, index+1, n, m)
visited[i] = false
}
}
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 15651๋ฒ / N๊ณผ M (3) [Go] (0) | 2020.07.21 |
---|---|
BOJ / 15650๋ฒ / N๊ณผ M (2) [Go] (0) | 2020.07.20 |
BOJ / 10814๋ฒ / ๋์ด์ ์ ๋ ฌ [Go] (0) | 2020.07.18 |
BOJ / 1181๋ฒ / ๋จ์ด ์ ๋ ฌ [Go] (0) | 2020.07.17 |
BOJ / 11651๋ฒ / ์ขํ ์ ๋ ฌํ๊ธฐ 2 [Go] (0) | 2020.07.14 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- BFS
- ์๋ฐ
- dfs
- ๋ฐฑ์ค
- python3
- AWS
- MongoDB
- ์๊ณ ๋ฆฌ์ฆ
- ๋ธ๋ฃจํธํฌ์ค
- java
- Macbook pro 2012 mid 13
- ballet
- ๋ฐ๋
- ๋งฅ๋ถํ๋ก
- go
- ๋งฅ๋ถ
- ๋ชฝ๊ณ ๋๋น
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- ์คํ
- ๋ถํ ์ ๋ณต
- ์๊ฐ๊ต์ฒด
- ํ๋ก์ด๋์์ฌ
- dp
- baekjoon
- ํด์๋งต
- ํ
- ์ด๋ถํ์
- Algorithm
- BOJ
- Golang
- Total
- Today
- Yesterday