标签:tco col def dice 范围 _for etc code nbsp
dp[i][j]表示前i个骰子到达数字总和j的方案数
dp[i][j] = Σdp[i-1][j-k],其中k是一个骰子能掷出的范围
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 };
Leetcode-1155 Number of Dice Rolls With Target Sum(掷骰子的N种方法)
标签:tco col def dice 范围 _for etc code nbsp
原文地址:https://www.cnblogs.com/Asurudo/p/11334549.html