1
[[nodiscard]] double step(int const A, int const B,2
std::unordered_map<int, std::unordered_map<int, double>> &Memo) {3
if (A <= 0) return B <= 0 ? 0.5 : 1.0;4
if (B <= 0) return 0.0;6
auto const AIt{Memo.find(A)};8
if (Memo.cend() != AIt) {9
auto const BIt{AIt->second.find(B)};10
if (AIt->second.cend() != BIt) return BIt->second;13
double M{step(A - 100, B, Memo)};14
M += step(A - 75, B - 25, Memo);15
M += step(A - 50, B - 50, Memo);16
M += step(A - 25, B - 75, Memo);17
return Memo[A][B] = 0.25 * M;22
double soupServings(int n) {23
if (n > 4750) return 1;25
std::unordered_map<int, std::unordered_map<int, double>> Memo{};26
return step(n, n, Memo);