37 lines
483 B
Go
37 lines
483 B
Go
//go:build ignore
|
|
|
|
// 指数型枚举:从 1-n 这 n 个整数中随机选取任意多个
|
|
package main
|
|
|
|
import "fmt"
|
|
|
|
var path []int
|
|
|
|
func dfs(x int, n int) { // x 是当前枚举到的位置
|
|
if x > n {
|
|
for i, v := range path {
|
|
if i > 0 {
|
|
fmt.Printf(" ")
|
|
}
|
|
fmt.Printf("%d", v)
|
|
}
|
|
fmt.Printf("\n")
|
|
return
|
|
}
|
|
|
|
// 不选
|
|
dfs(x+1, n)
|
|
|
|
// 选
|
|
path = append(path, x)
|
|
dfs(x+1, n)
|
|
|
|
path = path[:len(path)-1]
|
|
}
|
|
|
|
func main() {
|
|
var n int
|
|
fmt.Scan(&n)
|
|
dfs(1, n)
|
|
}
|