排列数字-dfs-golang
blablabla
golang
package main
import "fmt"
var n int
var path []int
var st []bool
func main(){
fmt.Scanf("%d", &n)
path, st = make([]int, n+1), make([]bool, n+1)
dfs(1)
}
func dfs(u int){
if u > n{
for i := 1; i <= n; i++{
fmt.Printf("%d ", path[i])
}
fmt.Println()
}
for i := 1; i <= n; i++{
if st[i] == false{
path[u] = i
st[i] = true
dfs(u+1)
st[i] = false
}
}
}