当前位置:网站首页>leetcode:6109. Number of people who know the secret [definition of DP]
leetcode:6109. Number of people who know the secret [definition of DP]
2022-07-04 14:27:00 【White speed Dragon King's review】

analysis
dp[i] It is defined as the first i Who just knows the secret
then dp[i] Is equal to dp[i - delay] To dp[i - forget] All and ( Specifically +1-1debug Besides, )
And then at the end of the day forget Before dp Sum of
ac code
class Solution:
def peopleAwareOfSecret(self, n: int, delay: int, forget: int) -> int:
MOD = 10 ** 9 + 7
ans = 0
# dp[i] Express The first i How many people just know the secret
dp = [0] * (n + 1)
#print(dp)
dp[1] = 1
for i in range(2, n + 1):
for j in range(i - forget + 1, i - delay + 1):
if j >= 1:
dp[i] += dp[j]
for i in range(forget):
ans += dp[n - i]
ans %= MOD
return ans
summary
dp[i] What does it mean
How to state transition
边栏推荐
- File creation, writing, reading, deletion (transfer) in go language
- Use of tiledlayout function in MATLAB
- Leetcode T48: rotating images
- Ml: introduction, principle, use method and detailed introduction of classic cases of snap value
- How to package QT and share exe
- Remove duplicate letters [greedy + monotonic stack (maintain monotonic sequence with array +len)]
- 利用Shap值进行异常值检测
- 失败率高达80%,企业数字化转型路上有哪些挑战?
- Industrial Internet has greater development potential and more industry scenarios
- 关于miui12.5 红米k20pro用au或者povo2出现问题的解决办法
猜你喜欢

Excel快速合并多行数据

Nowcoder rearrange linked list

Ruiji takeout notes

Digi重启XBee-Pro S2C生产,有些差别需要注意

How to package QT and share exe
![[matlab] summary of conv, filter, conv2, Filter2 and imfilter convolution functions](/img/7a/9b559313b407f9a12cbaed7bebd4dc.png)
[matlab] summary of conv, filter, conv2, Filter2 and imfilter convolution functions

Count the running time of PHP program and set the maximum running time of PHP

Use of tiledlayout function in MATLAB
![Supprimer les lettres dupliquées [avidité + pile monotone (maintenir la séquence monotone avec un tableau + Len)]](/img/af/a1dcba6f45eb4ccc668cd04a662e9c.png)
Supprimer les lettres dupliquées [avidité + pile monotone (maintenir la séquence monotone avec un tableau + Len)]

vscode 常用插件汇总
随机推荐
使用CLion编译OGLPG-9th-Edition源码
R language dplyr package summary_ If function calculates the mean and median of all numerical data columns in dataframe data, and summarizes all numerical variables based on conditions
PyTorch的自动求导机制详细解析,PyTorch的核心魔法
R语言使用epiDisplay包的dotplot函数通过点图的形式可视化不同区间数据点的频率、使用by参数指定分组参数可视化不同分组的点图分布
Rich text editing: wangeditor tutorial
R language ggplot2 visualization: gganimate package creates animated graph (GIF) and uses anim_ The save function saves the GIF visual animation
迅为IMX6Q开发板QT系统移植tinyplay
關於miui12.5 紅米k20pro用au或者povo2出現問題的解决辦法
Common content type correspondence table
R语言使用dplyr包的group_by函数和summarise函数基于分组变量计算目标变量的均值、标准差
Leetcode T48:旋转图像
流行框架:Glide的使用
Digi重启XBee-Pro S2C生产,有些差别需要注意
Chapter 17 process memory
WT588F02B-8S(C006_03)单芯片语音ic方案为智能门铃设计降本增效赋能
[matlab] summary of conv, filter, conv2, Filter2 and imfilter convolution functions
docker-compose公网部署redis哨兵模式
ARouter的使用
The game goes to sea and operates globally
富文本编辑:wangEditor使用教程