1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 11:08:15 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/掷骰子的N种方法 [number-of-dice-rolls-with-target-sum].html
2022-03-29 12:43:11 +08:00

42 lines
1.4 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>