Class Solution
java.lang.Object
g1101_1200.s1155_number_of_dice_rolls_with_target_sum.Solution
1155 - Number of Dice Rolls With Target Sum.<p>Medium</p>
<p>You have <code>n</code> dice and each die has <code>k</code> faces numbered from <code>1</code> to <code>k</code>.</p>
<p>Given three integers <code>n</code>, <code>k</code>, and <code>target</code>, return <em>the number of possible ways (out of the</em> <code>k<sup>n</sup></code> <em>total ways)</em> <em>to roll the dice so the sum of the face-up numbers equals</em> <code>target</code>. Since the answer may be too large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> n = 1, k = 6, target = 3</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Explanation:</strong> You throw one die with 6 faces.</p>
<p>There is only one way to get a sum of 3.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> n = 2, k = 6, target = 7</p>
<p><strong>Output:</strong> 6</p>
<p><strong>Explanation:</strong> You throw two dice, each with 6 faces.</p>
<p>There are 6 ways to get a sum of 7: 1+6, 2+5, 3+4, 4+3, 5+2, 6+1.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> n = 30, k = 30, target = 500</p>
<p><strong>Output:</strong> 222616187</p>
<p><strong>Explanation:</strong> The answer must be returned modulo 10<sup>9</sup> + 7.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= n, k <= 30</code></li>
<li><code>1 <= target <= 1000</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
numRollsToTarget
public int numRollsToTarget(int n, int k, int target)
-