ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ 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 {
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] || index > 0 && result[index-1] > i {
continue
}
visited[i] = true
result[index] = i
sequence(writer, visited, result, index+1, n, m)
visited[i] = false
}
}
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 15652๋ฒ / N๊ณผ M (4) [Go] (0) | 2020.07.22 |
---|---|
BOJ / 15651๋ฒ / N๊ณผ M (3) [Go] (0) | 2020.07.21 |
BOJ / 15649๋ฒ / N๊ณผ M (1) [Go] (0) | 2020.07.19 |
BOJ / 10814๋ฒ / ๋์ด์ ์ ๋ ฌ [Go] (0) | 2020.07.18 |
BOJ / 1181๋ฒ / ๋จ์ด ์ ๋ ฌ [Go] (0) | 2020.07.17 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- ์๋ฐ
- dfs
- AWS
- ํ๋ก์ด๋์์ฌ
- java
- ๋ฐ๋
- ์ด๋ถํ์
- ๋งฅ๋ถ
- ๋ถํ ์ ๋ณต
- ํด์๋งต
- ๋ฐฑ์ค
- Algorithm
- baekjoon
- ๋งฅ๋ถํ๋ก
- ๋ชฝ๊ณ ๋๋น
- ์๊ณ ๋ฆฌ์ฆ
- Macbook pro 2012 mid 13
- python3
- MongoDB
- ํ
- ์คํ
- BOJ
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- ์๊ฐ๊ต์ฒด
- BFS
- ๋ธ๋ฃจํธํฌ์ค
- dp
- ballet
- go
- Golang
- Total
- Today
- Yesterday