Leetcode-1155 Number of Dice Rolls With Target Sum (N ways dice)

DP [i] [j] represents the number of programs before the die reaches an i-th digital sum of j

dp [i] [j] = Σdp [i-1] [jk], where k is a throw of the dice can range

 1 #define _for(i,a,b) for(int i = (a);i < b;i ++)
 2 
 3 class Solution
 4 {
 5     public:
 6         int dp[31][1003];
 7         int numRollsToTarget(int d, int f, int target)
 8         {
 9             _for(k,1,f+1)
10                 dp[0][k] = 1;
11             _for(i,1,d)
12                 _for(j,1,target+1)
13                     _for(k,1,f+1)
14                     {
15                         if(j-k>0)
16                             dp[i][j] += dp[i-1][j-k];
17                         dp[i][j] %= 1000000007;
18                     }
19             return dp[d-1][target];
20         }
21 };

 

Guess you like

Origin www.cnblogs.com/Asurudo/p/11334549.html