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) }