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)/和带限制的子多重集合的数目 [count-of-sub-multisets-with-bounded-sum].html
2023-10-15 20:45:13 +08:00

51 lines
2.1 KiB
HTML
Raw Permalink 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>给你一个下标从 <strong>0</strong>&nbsp;开始的非负整数数组&nbsp;<code>nums</code>&nbsp;和两个整数&nbsp;<code>l</code>&nbsp;<code>r</code>&nbsp;</p>
<p>请你返回&nbsp;<code>nums</code>&nbsp;中子多重集合的和在闭区间&nbsp;<code>[l, r]</code>&nbsp;之间的 <strong>子多重集合的数目</strong></p>
<p>由于答案可能很大,请你将答案对&nbsp;<code>10<sup>9 </sup>+ 7</code>&nbsp;取余后返回。</p>
<p><strong>子多重集合</strong> 指的是从数组中选出一些元素构成的 <strong>无序</strong>&nbsp;集合,每个元素 <code>x</code>&nbsp;出现的次数可以是&nbsp;<code>0, 1, ..., occ[x]</code>&nbsp;次,其中&nbsp;<code>occ[x]</code>&nbsp;是元素&nbsp;<code>x</code>&nbsp;在数组中的出现次数。</p>
<p><b>注意:</b></p>
<ul>
<li>如果两个子多重集合中的元素排序后一模一样,那么它们两个是相同的&nbsp;<strong>子多重集合</strong>&nbsp;</li>
<li><strong></strong>&nbsp;集合的和是 <code>0</code>&nbsp;</li>
</ul>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<b>输入:</b>nums = [1,2,2,3], l = 6, r = 6
<b>输出:</b>1
<b>解释:</b>唯一和为 6 的子集合是 {1, 2, 3} 。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<b>输入:</b>nums = [2,1,4,2,7], l = 1, r = 5
<b>输出:</b>7
<b>解释:</b>和在闭区间 [1, 5] 之间的子多重集合为 {1} {2} {4} {2, 2} {1, 2} {1, 4} 和 {1, 2, 2} 。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<b>输入:</b>nums = [1,2,1,3,5,2], l = 3, r = 5
<b>输出:</b>9
<b>解释:</b>和在闭区间 [3, 5] 之间的子多重集合为 {3} {5} {1, 2} {1, 3} {2, 2} {2, 3} {1, 1, 2} {1, 1, 3} 和 {1, 2, 2} 。</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 2 * 10<sup>4</sup></code></li>
<li><code>0 &lt;= nums[i] &lt;= 2 * 10<sup>4</sup></code></li>
<li><code>nums</code> 的和不超过&nbsp;<code>2 * 10<sup>4</sup></code></li>
<li><code>0 &lt;= l &lt;= r &lt;= 2 * 10<sup>4</sup></code></li>
</ul>