Java dp clean solution
Slow Version\n\nclass Solution {\n    int mod = (int)1e9 + 7;\n    public int dieSimulator(int n, int[] rollMax) {\n        long res=0;\n        int longest=0;\
Slow Version\n```\nclass Solution {\n    int mod = (int)1e9 + 7;\n    public int dieSimulator(int n, int[] rollMax) {\n        long res=0;\n        int longest=0;\n        for(int x:rollMax)longest=Math.max(x,longest);\n        long dp[][][]=new long[n][6][longest+1];\n        for(int i=0;i<6;i++){\n            dp[0][i][1]=1;\n        }\n        for(int day=1;day<n;day++){\n            for(int i=0;i<6;i++){\n                long sum=0;\n                for(int k=2;k<=rollMax[i];k++){\n                    dp[day][i][k]=dp[day-1][i][k-1];\n                }\n                for(int j=0;j<6;j++){\n                    if(i==j)continue;\n                    for(int k=1;k<=rollMax[j];k++){\n                        sum+=dp[day-1][j][k];\n                        sum%=mod;\n                    }\n                }\n                \n                dp[day][i][1]=sum;\n            }\n        }\n        for(int i=0;i<6;i++){\n            for(int k=0;k<=rollMax[i];k++){\n                res+=dp[dp.length-1][i][k];\n                res%=mod;\n            }\n        }\n        return (int)res;\n    }\n}\n```\n\nFast Version\n```\nclass Solution {\n    int mod = (int)1e9 + 7;\n    public int dieSimulator(int n, int[] rollMax) {\n        long res=0;\n        int longest=0;\n        for(int x:rollMax)longest=Math.max(x,longest);\n        long dp[][][]=new long[n][6][longest+1];\n        long sums[][]=new long[n][6];\n        for(int i=0;i<6;i++){\n            dp[0][i][1]=1;\n            sums[0][i]=1;\n        }\n        for(int day=1;day<n;day++){\n            for(int i=0;i<6;i++){\n                long total=0;\n                long sum=0;\n                for(int k=2;k<=rollMax[i];k++){\n                    dp[day][i][k]=dp[day-1][i][k-1];\n                    total+=dp[day][i][k];\n                    total%=mod;\n                }\n                for(int j=0;j<6;j++){\n                    if(i==j)continue;\n                    sum+=sums[day-1][j];\n                    sum%=mod;\n                }\n                dp[day][i][1]=sum;\n                total=(total+sum)%mod;\n                sums[day][i]=total;\n            }\n        }\n        for(int i=0;i<6;i++){\n            for(int k=0;k<=rollMax[i];k++){\n                res+=dp[dp.length-1][i][k];\n                res%=mod;\n            }\n        }\n        return (int)res;\n    }\n}\n```
[]