1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/掷骰子等于目标和的方法数 [number-of-dice-rolls-with-target-sum].html

42 lines
1.5 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>这里有&nbsp;<code>n</code>&nbsp;个一样的骰子,每个骰子上都有&nbsp;<code>k</code>&nbsp;个面,分别标号为&nbsp;<code>1</code>&nbsp;<code>k</code></p>
<p>给定三个整数 <code>n</code> ,&nbsp; <code>k</code>&nbsp;<code>target</code>&nbsp;,返回可能的方式(从总共<em>&nbsp;</em><code>k<sup>n</sup></code><em>&nbsp;</em>种方式中)滚动骰子的数量,使正面朝上的数字之和等于<em>&nbsp;</em><code>target</code>&nbsp;</p>
<p>答案可能很大,你需要对&nbsp;<code>10<sup>9</sup>&nbsp;+ 7</code> <strong>取模</strong>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>n = 1, k = 6, target = 3
<strong>输出:</strong>1
<strong>解释:</strong>你扔一个有 6 个面的骰子。
得到 3 的和只有一种方法。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>n = 2, k = 6, target = 7
<strong>输出:</strong>6
<strong>解释:</strong>你扔两个骰子,每个骰子有 6 个面。
得到 7 的和有 6 种方法1+6 2+5 3+4 4+3 5+2 6+1。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>n = 30, k = 30, target = 500
<strong>输出:</strong>222616187
<strong>解释:</strong>返回的结果必须是对 10<sup>9</sup> + 7 取模。</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= n, k &lt;= 30</code></li>
<li><code>1 &lt;= target &lt;= 1000</code></li>
</ul>