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

package leetcode;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

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

    private static int dieSimulator(int n, int[] rollMax, Map<String, Integer> memo) {
        if (n == 0) {
            return 1;
        }
        String key = n + "," + Arrays.toString(rollMax);
        if (memo.containsKey(key)) {
            return memo.get(key);
        }
        int count = 0;
        for (int i = 1; i <= 6; i++) {
            if (rollMax[i - 1] > 0) {
                rollMax[i - 1]--;
                count += dieSimulator(n - 1, rollMax, memo);
                rollMax[i - 1]++;
            }
        }
        memo.put(key, count);
        return count;
    }

    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
//        System.out.println(prob.dieSimulator(1, new int[]{1,1,1,1,1,1})); // 6
    }
}

Update problem 1223