题目描述
fmt会超时
样例
package main
import (
"fmt"
"strconv"
)
var n int
func dfs(isUsed []int, currentPath string) {
if len(currentPath) == n*2 {
fmt.Println(currentPath)
return
}
for i := 1; i <= n; i++ {
if isUsed[i] == 1 {
continue
}
isUsed[i] = 1
currentPath += strconv.Itoa(i) + " "
dfs(isUsed, currentPath)
currentPath = currentPath[:len(currentPath)-2]
isUsed[i] = 0
}
}
func main() {
fmt.Scanf("%d", &n)
dfs(make([]int, n+1), "")
}