[InterviewBit] Dice Rolls

Dice Rolls

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
long long dp[1010101], mod = 1e9 + 7;
long long helper(int k) {
if(k < 0) return 0;
long long& res = dp[k];
if(res != -1) return res;
res = 0;
for(int i = 1; i <= 6; i++) res = (res + helper(k-i)) % mod;
return res;
}
int Solution::solve(int A) {
memset(dp,-1,sizeof dp);
dp[0] = 1;
return helper(A);
}


Author: Song Hayoung
Link: https://songhayoung.github.io/2022/11/21/PS/interviewbit/dice-rolls/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.