1155. 掷骰子的N种方法
作者:互联网
花了一个小时吧。。怪自己太菜了,还是把这道dp做了
1 int numRollsToTarget(int d, int f, int target) { 2 int mod = 7 + 1e9; 3 if (d == 1 && f >= target) 4 return 1; 5 else if (d == 1 && f < target) 6 return 0; 7 vector<vector<int>> dp(d+1, vector<int>(target+1, 0)); 8 for (int i = 0; i <= target; i++) 9 dp[1][i] = 0; 10 11 for (int i = 1; i <= min(f,target); i++) 12 dp[1][i] = 1; 13 for (int i = 2; i <= d; i++) 14 { 15 for (int j = i; j <= min(i * f,target); j++) 16 { 17 for (int k = 1; k <= min(f, j-1); k++) 18 { 19 dp[i][j] += dp[i - 1][j - k]; 20 dp[i][j] %= mod; 21 } 22 } 23 } 24 return dp[d][target]; 25 }
标签:return,target,1155,掷骰子,int,vector,&&,方法,dp 来源: https://www.cnblogs.com/zouma/p/11674001.html