package leetcode;

/**
 * https://leetcode.com/problems/dice-roll-simulation/
 */
public class Problem1223 {
    public int dieSimulator(int n, int[] rollMax) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1223 prob = new Problem1223();
        System.out.println(prob.dieSimulator(2, new int[]{1,1,2,2,2,3})); // 34
        System.out.println(prob.dieSimulator(2, new int[]{1,1,1,1,1,1})); // 30
        System.out.println(prob.dieSimulator(3, new int[]{1,1,1,2,2,3})); // 181
    }
}

@@ -12,16 +12,90 @@
 tcode;%0A%0A
+import java.util.Arrays;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 /**%0A * h
@@ -240,32 +240,647 @@
     
-// TODO
+return dieSimulator(n, rollMax, new HashMap%3C%3E());
 %0A    
+%7D%0A%0A
     
-return 0
+private static int dieSimulator(int n, int%5B%5D rollMax, Map%3CString, Integer%3E memo) %7B%0A        if (n == 0) %7B%0A            return 1;%0A        %7D%0A        String key = n + %22,%22 + Arrays.toString(rollMax);%0A        if (memo.containsKey(key)) %7B%0A            return memo.get(key);%0A        %7D%0A        int count = 0;%0A        for (int i = 1; i %3C= 6; i++) %7B%0A            if (rollMax%5Bi - 1%5D %3E 0) %7B%0A                rollMax%5Bi - 1%5D--;%0A                count += dieSimulator(n - 1, rollMax, memo);%0A                rollMax%5Bi - 1%5D++;%0A            %7D%0A        %7D%0A        memo.put(key, count);%0A        return count
 ;%0A  
@@ -975,16 +975,18 @@
 1223();%0A
+//
         
@@ -1057,16 +1057,18 @@
 ; // 34%0A
+//
         
@@ -1220,16 +1220,97 @@
  // 181%0A
+//        System.out.println(prob.dieSimulator(1, new int%5B%5D%7B1,1,1,1,1,1%7D)); // 6%0A
     %7D%0A%7D%0A

Update problem 1223