leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0808.cpp (476B)


      1 class Solution {
      2     double dp[200][200] = {0};
      3 
      4     double calc(int a, int b) {
      5         if (a <= 0 && b <= 0) return 0.5;
      6         if (a <= 0) return 1;
      7         if (b <= 0) return 0;
      8         if (dp[a][b] > 0) return dp[a][b];
      9         return dp[a][b] =
     10                    0.25 * (calc(a - 4, b) + calc(a - 3, b - 1) + calc(a - 2, b - 2) + calc(a - 1, b - 3));
     11     }
     12 
     13   public:
     14     double soupServings(int n) { return n > 4800 ? 1.0 : calc(ceil(n / 25.0), ceil(n / 25.0)); }
     15 };