package leetcode;

/**
 * https://leetcode.com/problems/soup-servings/
 */
public class Problem808 {
    public double soupServings(int N) {
        // TODO
        return soupServings(N, N);
    }

    private double soupServings(int a, int b) {
        if (a <= 0 && b <= 0) {
            return 0.5;
        }
        if (a <= 0) {
            return 0;
        }
        if (b <= 0) {
            return 1;
        }
        double result = 0.25 * (soupServings(a, b - 100) +
            soupServings(a - 25, b - 75) +
            soupServings(a - 50, b - 50) +
            soupServings(a - 75, b - 25));
        return result;
    }

    public static void main(String[] args) {
        Problem808 prob = new Problem808();
        System.out.println(prob.soupServings(50)); // 0.625
        System.out.println(prob.soupServings(40)); // 0.625
        System.out.println(prob.soupServings(100)); // 0.71875
    }
}

@@ -146,15 +146,197 @@
     
-// TODO
+int div = N / 25;%0A        int mod = N %25 25;%0A        N = div + (mod == 0 ? 0 : 1);%0A        if (N %3E= 500) %7B%0A            return 1;%0A        %7D%0A        Double%5B%5D%5B%5D memo = new Double%5BN + 1%5D%5BN + 1%5D;
 %0A   
@@ -364,16 +364,22 @@
 ngs(N, N
+, memo
 );%0A    %7D
@@ -424,16 +424,33 @@
 a, int b
+, Double%5B%5D%5B%5D memo
 ) %7B%0A    
@@ -552,17 +552,17 @@
  return 
-0
+1
 ;%0A      
@@ -598,33 +598,108 @@
          return 
-1
+0;%0A        %7D%0A        if (memo%5Ba%5D%5Bb%5D != null) %7B%0A            return memo%5Ba%5D%5Bb%5D
 ;%0A        %7D%0A    
@@ -730,34 +730,8 @@
  * (
-soupServings(a, b - 100) +
 %0A   
@@ -760,18 +760,18 @@
 a - 
-25, b - 75
+4, b, memo
 ) +%0A
@@ -803,18 +803,22 @@
 a - 
-50
+3
 , b - 
-50
+1, memo
 ) +%0A
@@ -850,323 +850,133 @@
 a - 
-75
+2
 , b - 2
-5));%0A        return result;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem808 prob = new Problem808();%0A        System.out.println(prob.soupServings(50)); // 0.625%0A        System.out.println(prob.soupServings(40)); // 0.625%0A        System.out.println(prob.soupServings(100)); // 0.71875
+, memo) +%0A            soupServings(a - 1, b - 3, memo)%0A        );%0A        memo%5Ba%5D%5Bb%5D = result;%0A        return result;
 %0A   

Solve problem 808