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