1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
| package main
import (
"fmt"
"log"
"net/http"
_ "net/http/pprof"
"os"
)
func FbnqDp(n int) (s int) {
dp := make([]int, n+1)
dp[1] = 1
for i := 2; i < n+1; i++ {
dp[i] = dp[i-2] + dp[i-1]
}
return dp[n]
}
func Fbnq(n int) (s int) {
if n <= 2 {
return 1
}
return Fbnq(n-1) + Fbnq(n-2)
}
func main() {
go func() {
if err := http.ListenAndServe(":6060", nil); err != nil {
log.Fatal(err)
}
os.Exit(0)
}()
http.HandleFunc("/hello", func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte("Hello World!"))
})
http.HandleFunc("/Fbnq", func(w http.ResponseWriter, req *http.Request) {
fmt.Println(Fbnq(10))
})
http.HandleFunc("/FbnqDp", func(w http.ResponseWriter, req *http.Request) {
fmt.Println(FbnqDp(10))
})
http.ListenAndServe(":8080", nil)
}
|