refactor: refactor project structure

This commit is contained in:
2025-09-01 09:13:32 +08:00
parent 524784a3c5
commit 9fec047d3f
42 changed files with 0 additions and 4 deletions

View File

@@ -0,0 +1,52 @@
package main
import ("fmt")
type Solution struct{
dp map[[2]int]float64
}
func NewSolution() *Solution{
return &Solution{dp: make(map[[2]int]float64)}
}
func (s *Solution) SoupServings(n int)float64{
if n > 5000{
return 1.0
}
n = (n+24) /25
return s.helper(n, n)
}
func (s * Solution) helper(a, b int) float64 {
if a <= 0 && b <= 0{
return 0.5
}
if a <= 0{
return 1.0
}
if b <= 0{
return 0
}
if val, exist := s.dp[[2]int{a, b}]; exist{
return val
}
probability := 0.25 * (
s.helper(a-4, b) +
s.helper(a-3, b-1) +
s.helper(a-2, b-2) +
s.helper(a-1, b-3))
s.dp[[2]int {a, b}] = probability
return probability
}
func main(){
Solution := NewSolution()
ans := Solution.SoupServings(100)
fmt.Println(ans)
}