-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay26.cpp
More file actions
25 lines (25 loc) · 758 Bytes
/
Day26.cpp
File metadata and controls
25 lines (25 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Solution {
public:
const int mod = (int)pow(10, 9) + 7;
int solve(vector<vector<int>>& temp, int n, int k, int target){
if(n == 0 && target == 0){
return 1;
}
if(n == 0 || target <= 0){
return 0;
}
if(temp[n][target] != -1){
return temp[n][target] % mod;
}
int ans = 0;
for(int i = 1; i <= k; i++){
ans = (ans + solve(temp, n-1, k, target - i)) % mod;
}
temp[n][target] = ans % mod;
return temp[n][target];
}
int numRollsToTarget(int n, int k, int target) {
vector<vector<int>> temp(n+1, vector<int>(target + 1, -1));
return solve(temp, n, k, target);
}
};