1155.cpp (572B)
1 class Solution { 2 static const int MOD = 1E9 + 7; 3 static int dp[31][1001]; 4 5 public: 6 Solution() { memset(dp, 0xFF, sizeof(dp)); } 7 int numRollsToTarget(int n, int k, int target, int crnt = 0) { 8 if (target < 0) return 0; 9 if (crnt == n) return target == 0; 10 if (dp[crnt][target] != -1) return dp[crnt][target]; 11 int res = 0; 12 for (int i = 1; i <= k; i++) { 13 res = (res + numRollsToTarget(n, k, target - i, crnt + 1)) % MOD; 14 } 15 return dp[crnt][target] = res; 16 } 17 }; 18 19 int Solution::dp[31][1001];