This commit is contained in:
2026-05-29 14:05:21 +08:00
parent b474274349
commit 894387f12f
4 changed files with 41 additions and 1 deletions
@@ -1 +1 @@
{"name":"Local: 1","url":"/home/wonder/code/algrithm/LC1/1.go","tests":[{"id":1780031224656,"input":"5","output":"8"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"/home/wonder/code/algrithm/LC1/1.go","group":"local","local":true} {"name":"Local: 1","url":"/home/wonder/code/algrithm/LC1/1.go","tests":[{"id":1780031224656,"input":"5","output":"8"},{"id":1780031582387,"input":"10","output":"89"},{"id":1780031822778,"input":"25","output":"121393"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"/home/wonder/code/algrithm/LC1/1.go","group":"local","local":true}
@@ -0,0 +1 @@
{"name":"Local: 2","url":"/home/wonder/code/algrithm/LC1/2.go","tests":[{"id":1780032920855,"input":"5","output":"\n5\n4\n4 5\n3\n3 5\n3 4\n3 4 5\n2\n2 5\n2 4\n2 4 5\n2 3\n2 3 5\n2 3 4\n2 3 4 5\n1\n1 5\n1 4\n1 4 5\n1 3\n1 3 5\n1 3 4\n1 3 4 5\n1 2\n1 2 5\n1 2 4\n1 2 4 5\n1 2 3\n1 2 3 5\n1 2 3 4\n1 2 3 4 5"},{"id":1780034280712,"input":"3","output":"\n3\n2\n2 3\n1\n1 3\n1 2\n1 2 3"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"/home/wonder/code/algrithm/LC1/2.go","group":"local","local":true}
+3
View File
@@ -1,3 +1,6 @@
//go:build ignore
// 跳台阶
package main package main
import "fmt" import "fmt"
+36
View File
@@ -0,0 +1,36 @@
//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)
}