We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b4b30a4 commit d18e0fcCopy full SHA for d18e0fc
solution/1155.Number of Dice Rolls With Target Sum/Solution.java
@@ -1,14 +1,14 @@
1
class Solution {
2
public int numRollsToTarget(int d, int f, int target) {
3
- int[] dp = new int[target + 1];
4
- dp[0] = 1;
+ int[][] dp = new int[d + 1][target + 1];
+ dp[0][0] = 1;
5
for (int i = 1; i <= d; ++i) {
6
- for (int j = target; j >= 1; --j) {
+ for (int j = 1; j <= target; ++j) {
7
for (int k = 1; k <= f && k <= j; ++k) {
8
- dp[j] = (dp[j] + dp[j - k]) % 1000000007;
+ dp[i][j] = (dp[i][j] + dp[i - 1][j - k]) % 1000000007;
9
}
10
11
12
- return dp[target];
+ return dp[d][target];
13
14
0 commit comments