1 Star 41 Fork 18

小墨/力扣题库(完整版)

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
find-the-n-th-value-after-k-seconds.html 2.11 KB
一键复制 编辑 原始数据 按行查看 历史
zhangbk1 提交于 2024-06-25 09:35 +08:00 . update
<p>You are given two integers <code>n</code> and <code>k</code>.</p>
<p>Initially, you start with an array <code>a</code> of <code>n</code> integers where <code>a[i] = 1</code> for all <code>0 &lt;= i &lt;= n - 1</code>. After each second, you simultaneously update each element to be the sum of all its preceding elements plus the element itself. For example, after one second, <code>a[0]</code> remains the same, <code>a[1]</code> becomes <code>a[0] + a[1]</code>, <code>a[2]</code> becomes <code>a[0] + a[1] + a[2]</code>, and so on.</p>
<p>Return the <strong>value</strong> of <code>a[n - 1]</code> after <code>k</code> seconds.</p>
<p>Since the answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 4, k = 5</span></p>
<p><strong>Output:</strong> <span class="example-io">56</span></p>
<p><strong>Explanation:</strong></p>
<table border="1">
<tbody>
<tr>
<th>Second</th>
<th>State After</th>
</tr>
<tr>
<td>0</td>
<td>[1,1,1,1]</td>
</tr>
<tr>
<td>1</td>
<td>[1,2,3,4]</td>
</tr>
<tr>
<td>2</td>
<td>[1,3,6,10]</td>
</tr>
<tr>
<td>3</td>
<td>[1,4,10,20]</td>
</tr>
<tr>
<td>4</td>
<td>[1,5,15,35]</td>
</tr>
<tr>
<td>5</td>
<td>[1,6,21,56]</td>
</tr>
</tbody>
</table>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 5, k = 3</span></p>
<p><strong>Output:</strong> <span class="example-io">35</span></p>
<p><strong>Explanation:</strong></p>
<table border="1">
<tbody>
<tr>
<th>Second</th>
<th>State After</th>
</tr>
<tr>
<td>0</td>
<td>[1,1,1,1,1]</td>
</tr>
<tr>
<td>1</td>
<td>[1,2,3,4,5]</td>
</tr>
<tr>
<td>2</td>
<td>[1,3,6,10,15]</td>
</tr>
<tr>
<td>3</td>
<td>[1,4,10,20,35]</td>
</tr>
</tbody>
</table>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= n, k &lt;= 1000</code></li>
</ul>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/coder-xiaomo/leetcode-problemset.git
git@gitee.com:coder-xiaomo/leetcode-problemset.git
coder-xiaomo
leetcode-problemset
力扣题库(完整版)
master

搜索帮助