Skip to content

Commit

Permalink
Create 1155. Number of Dice Rolls With Target Sum (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chayandas07 authored Dec 26, 2023
2 parents 4765624 + 43d1f59 commit 878733a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions 1155. Number of Dice Rolls With Target Sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution {
int dp[31][1001];
int rec(int n,int k,int target){
if(n==0) return target==0;
if(dp[n][target]!=-1) return dp[n][target];
int ans = 0, mod = 1e9+7;
for(int i=1;i<=min(k,target);i++){
ans=(0LL+ans+rec(n-1,k,target-i))%mod;
}
return dp[n][target] = ans;
}
public:
int numRollsToTarget(int n, int k, int target) {
memset(dp, -1, sizeof dp);
return rec(n,k,target);
}
};

0 comments on commit 878733a

Please sign in to comment.