Skip to content

Commit d3da124

Browse files
authored
feat: add biweekly contest 117 (doocs#1955)
1 parent 9ccbf99 commit d3da124

File tree

14 files changed

+720
-0
lines changed

14 files changed

+720
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# [2928. 给小朋友们分糖果 I](https://leetcode.cn/problems/distribute-candies-among-children-i)
2+
3+
[English Version](/solution/2900-2999/2928.Distribute%20Candies%20Among%20Children%20I/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你两个正整数&nbsp;<code>n</code> 和&nbsp;<code>limit</code>&nbsp;。</p>
10+
11+
<p>请你将 <code>n</code>&nbsp;颗糖果分给 <code>3</code>&nbsp;位小朋友,确保没有任何小朋友得到超过 <code>limit</code>&nbsp;颗糖果,请你返回满足此条件下的&nbsp;<strong>总方案数</strong>&nbsp;。</p>
12+
13+
<p>&nbsp;</p>
14+
15+
<p><strong class="example">示例 1:</strong></p>
16+
17+
<pre>
18+
<b>输入:</b>n = 5, limit = 2
19+
<b>输出:</b>3
20+
<b>解释:</b>总共有 3 种方法分配 5 颗糖果,且每位小朋友的糖果数不超过 2 :(1, 2, 2) ,(2, 1, 2) 和 (2, 2, 1) 。
21+
</pre>
22+
23+
<p><strong class="example">示例 2:</strong></p>
24+
25+
<pre>
26+
<b>输入:</b>n = 3, limit = 3
27+
<b>输出:</b>10
28+
<b>解释:</b>总共有 10 种方法分配 3 颗糖果,且每位小朋友的糖果数不超过 3 :(0, 0, 3) ,(0, 1, 2) ,(0, 2, 1) ,(0, 3, 0) ,(1, 0, 2) ,(1, 1, 1) ,(1, 2, 0) ,(2, 0, 1) ,(2, 1, 0) 和 (3, 0, 0) 。
29+
</pre>
30+
31+
<p>&nbsp;</p>
32+
33+
<p><strong>提示:</strong></p>
34+
35+
<ul>
36+
<li><code>1 &lt;= n &lt;= 50</code></li>
37+
<li><code>1 &lt;= limit &lt;= 50</code></li>
38+
</ul>
39+
40+
## 解法
41+
42+
<!-- 这里可写通用的实现逻辑 -->
43+
44+
<!-- tabs:start -->
45+
46+
### **Python3**
47+
48+
<!-- 这里可写当前语言的特殊实现逻辑 -->
49+
50+
```python
51+
52+
```
53+
54+
### **Java**
55+
56+
<!-- 这里可写当前语言的特殊实现逻辑 -->
57+
58+
```java
59+
60+
```
61+
62+
### **C++**
63+
64+
```cpp
65+
66+
```
67+
68+
### **Go**
69+
70+
```go
71+
72+
```
73+
74+
### **...**
75+
76+
```
77+
78+
```
79+
80+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# [2928. Distribute Candies Among Children I](https://leetcode.com/problems/distribute-candies-among-children-i)
2+
3+
[中文文档](/solution/2900-2999/2928.Distribute%20Candies%20Among%20Children%20I/README.md)
4+
5+
## Description
6+
7+
<p>You are given two positive integers <code>n</code> and <code>limit</code>.</p>
8+
9+
<p>Return <em>the <strong>total number</strong> of ways to distribute </em><code>n</code> <em>candies among </em><code>3</code><em> children such that no child gets more than </em><code>limit</code><em> candies.</em></p>
10+
11+
<p>&nbsp;</p>
12+
<p><strong class="example">Example 1:</strong></p>
13+
14+
<pre>
15+
<strong>Input:</strong> n = 5, limit = 2
16+
<strong>Output:</strong> 3
17+
<strong>Explanation:</strong> There are 3 ways to distribute 5 candies such that no child gets more than 2 candies: (1, 2, 2), (2, 1, 2) and (2, 2, 1).
18+
</pre>
19+
20+
<p><strong class="example">Example 2:</strong></p>
21+
22+
<pre>
23+
<strong>Input:</strong> n = 3, limit = 3
24+
<strong>Output:</strong> 10
25+
<strong>Explanation:</strong> There are 10 ways to distribute 3 candies such that no child gets more than 3 candies: (0, 0, 3), (0, 1, 2), (0, 2, 1), (0, 3, 0), (1, 0, 2), (1, 1, 1), (1, 2, 0), (2, 0, 1), (2, 1, 0) and (3, 0, 0).
26+
</pre>
27+
28+
<p>&nbsp;</p>
29+
<p><strong>Constraints:</strong></p>
30+
31+
<ul>
32+
<li><code>1 &lt;= n &lt;= 50</code></li>
33+
<li><code>1 &lt;= limit &lt;= 50</code></li>
34+
</ul>
35+
36+
## Solutions
37+
38+
<!-- tabs:start -->
39+
40+
### **Python3**
41+
42+
```python
43+
44+
```
45+
46+
### **Java**
47+
48+
```java
49+
50+
```
51+
52+
### **C++**
53+
54+
```cpp
55+
56+
```
57+
58+
### **Go**
59+
60+
```go
61+
62+
```
63+
64+
### **...**
65+
66+
```
67+
68+
```
69+
70+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# [2929. 给小朋友们分糖果 II](https://leetcode.cn/problems/distribute-candies-among-children-ii)
2+
3+
[English Version](/solution/2900-2999/2929.Distribute%20Candies%20Among%20Children%20II/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你两个正整数&nbsp;<code>n</code> 和&nbsp;<code>limit</code>&nbsp;。</p>
10+
11+
<p>请你将 <code>n</code>&nbsp;颗糖果分给 <code>3</code>&nbsp;位小朋友,确保没有任何小朋友得到超过 <code>limit</code>&nbsp;颗糖果,请你返回满足此条件下的&nbsp;<strong>总方案数</strong>&nbsp;。</p>
12+
13+
<p>&nbsp;</p>
14+
15+
<p><strong class="example">示例 1:</strong></p>
16+
17+
<pre>
18+
<b>输入:</b>n = 5, limit = 2
19+
<b>输出:</b>3
20+
<b>解释:</b>总共有 3 种方法分配 5 颗糖果,且每位小朋友的糖果数不超过 2 :(1, 2, 2) ,(2, 1, 2) 和 (2, 2, 1) 。
21+
</pre>
22+
23+
<p><strong class="example">示例 2:</strong></p>
24+
25+
<pre>
26+
<b>输入:</b>n = 3, limit = 3
27+
<b>输出:</b>10
28+
<b>解释:</b>总共有 10 种方法分配 3 颗糖果,且每位小朋友的糖果数不超过 3 :(0, 0, 3) ,(0, 1, 2) ,(0, 2, 1) ,(0, 3, 0) ,(1, 0, 2) ,(1, 1, 1) ,(1, 2, 0) ,(2, 0, 1) ,(2, 1, 0) 和 (3, 0, 0) 。
29+
</pre>
30+
31+
<p>&nbsp;</p>
32+
33+
<p><strong>提示:</strong></p>
34+
35+
<ul>
36+
<li><code>1 &lt;= n &lt;= 10<sup>6</sup></code></li>
37+
<li><code>1 &lt;= limit &lt;= 10<sup>6</sup></code></li>
38+
</ul>
39+
40+
## 解法
41+
42+
<!-- 这里可写通用的实现逻辑 -->
43+
44+
<!-- tabs:start -->
45+
46+
### **Python3**
47+
48+
<!-- 这里可写当前语言的特殊实现逻辑 -->
49+
50+
```python
51+
52+
```
53+
54+
### **Java**
55+
56+
<!-- 这里可写当前语言的特殊实现逻辑 -->
57+
58+
```java
59+
60+
```
61+
62+
### **C++**
63+
64+
```cpp
65+
66+
```
67+
68+
### **Go**
69+
70+
```go
71+
72+
```
73+
74+
### **...**
75+
76+
```
77+
78+
```
79+
80+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# [2929. Distribute Candies Among Children II](https://leetcode.com/problems/distribute-candies-among-children-ii)
2+
3+
[中文文档](/solution/2900-2999/2929.Distribute%20Candies%20Among%20Children%20II/README.md)
4+
5+
## Description
6+
7+
<p>You are given two positive integers <code>n</code> and <code>limit</code>.</p>
8+
9+
<p>Return <em>the <strong>total number</strong> of ways to distribute </em><code>n</code> <em>candies among </em><code>3</code><em> children such that no child gets more than </em><code>limit</code><em> candies.</em></p>
10+
11+
<p>&nbsp;</p>
12+
<p><strong class="example">Example 1:</strong></p>
13+
14+
<pre>
15+
<strong>Input:</strong> n = 5, limit = 2
16+
<strong>Output:</strong> 3
17+
<strong>Explanation:</strong> There are 3 ways to distribute 5 candies such that no child gets more than 2 candies: (1, 2, 2), (2, 1, 2) and (2, 2, 1).
18+
</pre>
19+
20+
<p><strong class="example">Example 2:</strong></p>
21+
22+
<pre>
23+
<strong>Input:</strong> n = 3, limit = 3
24+
<strong>Output:</strong> 10
25+
<strong>Explanation:</strong> There are 10 ways to distribute 3 candies such that no child gets more than 3 candies: (0, 0, 3), (0, 1, 2), (0, 2, 1), (0, 3, 0), (1, 0, 2), (1, 1, 1), (1, 2, 0), (2, 0, 1), (2, 1, 0) and (3, 0, 0).
26+
</pre>
27+
28+
<p>&nbsp;</p>
29+
<p><strong>Constraints:</strong></p>
30+
31+
<ul>
32+
<li><code>1 &lt;= n &lt;= 10<sup>6</sup></code></li>
33+
<li><code>1 &lt;= limit &lt;= 10<sup>6</sup></code></li>
34+
</ul>
35+
36+
## Solutions
37+
38+
<!-- tabs:start -->
39+
40+
### **Python3**
41+
42+
```python
43+
44+
```
45+
46+
### **Java**
47+
48+
```java
49+
50+
```
51+
52+
### **C++**
53+
54+
```cpp
55+
56+
```
57+
58+
### **Go**
59+
60+
```go
61+
62+
```
63+
64+
### **...**
65+
66+
```
67+
68+
```
69+
70+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# [2930. 重新排列后包含指定子字符串的字符串数目](https://leetcode.cn/problems/number-of-strings-which-can-be-rearranged-to-contain-substring)
2+
3+
[English Version](/solution/2900-2999/2930.Number%20of%20Strings%20Which%20Can%20Be%20Rearranged%20to%20Contain%20Substring/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个整数&nbsp;<code>n</code>&nbsp;。</p>
10+
11+
<p>如果一个字符串&nbsp;<code>s</code>&nbsp;只包含小写英文字母,<strong>且</strong>&nbsp;将 <code>s</code>&nbsp;的字符重新排列后,新字符串包含&nbsp;<strong>子字符串</strong>&nbsp;<code>"leet"</code> ,那么我们称字符串 <code>s</code>&nbsp;是一个 <strong>好</strong>&nbsp;字符串。</p>
12+
13+
<p>比方说:</p>
14+
15+
<ul>
16+
<li>字符串&nbsp;<code>"lteer"</code>&nbsp;是好字符串,因为重新排列后可以得到&nbsp;<code>"leetr"</code>&nbsp;。</li>
17+
<li><code>"letl"</code>&nbsp;不是好字符串,因为无法重新排列并得到子字符串&nbsp;<code>"leet"</code>&nbsp;。</li>
18+
</ul>
19+
20+
<p>请你返回长度为 <code>n</code>&nbsp;的好字符串 <strong>总</strong>&nbsp;数目。</p>
21+
22+
<p>由于答案可能很大,将答案对<strong>&nbsp;</strong><code>10<sup>9</sup> + 7</code>&nbsp;<strong>取余</strong>&nbsp;后返回。</p>
23+
24+
<p><strong>子字符串</strong>&nbsp;是一个字符串中一段连续的字符序列。</p>
25+
26+
<div class="notranslate" style="all: initial;">&nbsp;</div>
27+
28+
<p><strong class="example">示例 1:</strong></p>
29+
30+
<pre>
31+
<b>输入:</b>n = 4
32+
<b>输出:</b>12
33+
<b>解释:</b>总共有 12 个字符串重新排列后包含子字符串 "leet" :"eelt" ,"eetl" ,"elet" ,"elte" ,"etel" ,"etle" ,"leet" ,"lete" ,"ltee" ,"teel" ,"tele" 和 "tlee" 。
34+
</pre>
35+
36+
<p><strong class="example">示例 2:</strong></p>
37+
38+
<pre>
39+
<b>输入:</b>n = 10
40+
<b>输出:</b>83943898
41+
<b>解释:</b>长度为 10 的字符串重新排列后包含子字符串 "leet" 的方案数为 526083947580 。所以答案为 526083947580 % (10<sup>9</sup> + 7) = 83943898 。
42+
</pre>
43+
44+
<p>&nbsp;</p>
45+
46+
<p><strong>提示:</strong></p>
47+
48+
<ul>
49+
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
50+
</ul>
51+
52+
## 解法
53+
54+
<!-- 这里可写通用的实现逻辑 -->
55+
56+
<!-- tabs:start -->
57+
58+
### **Python3**
59+
60+
<!-- 这里可写当前语言的特殊实现逻辑 -->
61+
62+
```python
63+
64+
```
65+
66+
### **Java**
67+
68+
<!-- 这里可写当前语言的特殊实现逻辑 -->
69+
70+
```java
71+
72+
```
73+
74+
### **C++**
75+
76+
```cpp
77+
78+
```
79+
80+
### **Go**
81+
82+
```go
83+
84+
```
85+
86+
### **...**
87+
88+
```
89+
90+
```
91+
92+
<!-- tabs:end -->

0 commit comments

Comments
 (0)