当前位置:网站首页>leetcode:6109. 知道秘密的人数【dp的定义】
leetcode:6109. 知道秘密的人数【dp的定义】
2022-07-04 12:52:00 【白速龙王的回眸】

分析
dp[i]定义为第i天刚知道秘密的人
然后dp[i]就等于dp[i - delay]到dp[i - forget]的所有和(具体+1-1debug再说)
然后最后的时候求到forget前的dp之和即可
ac code
class Solution:
def peopleAwareOfSecret(self, n: int, delay: int, forget: int) -> int:
MOD = 10 ** 9 + 7
ans = 0
# dp[i] 表示 第i天多少人刚知道秘密
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
总结
dp[i]表示的是什么东西
怎么状态转移
边栏推荐
- Leetcode T49: 字母异位词分组
- Whether the loyalty agreement has legal effect
- 游戏出海,全球化运营
- Ml: introduction, principle, use method and detailed introduction of classic cases of snap value
- R language uses dplyr package group_ The by function and the summarize function calculate the mean and standard deviation of the target variables based on the grouped variables
- Error in find command: paths must precede expression (turn)
- Hardware Basics - diode Basics
- Understand chisel language thoroughly 08. Chisel Foundation (V) -- wire, REG and IO, and how to understand chisel generation hardware
- nowcoder重排链表
- Understand chisel language thoroughly 04. Chisel Foundation (I) - signal type and constant
猜你喜欢

China Post technology rushes to the scientific innovation board: the annual revenue is 2.058 billion, and the postal group is the major shareholder

Haobo medical sprint technology innovation board: annual revenue of 260million Yonggang and Shen Zhiqun are the actual controllers

【信息检索】分类和聚类的实验

【MySQL从入门到精通】【高级篇】(五)MySQL的SQL语句执行流程

为什么图片传输要使用base64编码

Understand chisel language thoroughly 12. Chisel project construction, operation and testing (IV) -- chisel test of chisel test

Vscode common plug-ins summary

实时数据仓库
![[antd step pit] antd form cooperates with input Form The height occupied by item is incorrect](/img/96/379d1692f9d3c05a7af2e938cbc5d7.png)
[antd step pit] antd form cooperates with input Form The height occupied by item is incorrect

软件测试之测试评估
随机推荐
Oppo find N2 product form first exposure: supplement all short boards
ML之shap:基于boston波士顿房价回归预测数据集利用Shap值对LiR线性回归模型实现可解释性案例
LiveData
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
商業智能BI財務分析,狹義的財務分析和廣義的財務分析有何不同?
R语言ggplot2可视化:gganimate包创建动画图(gif)、使用anim_save函数保存gif可视化动图
R language uses the mutation function of dplyr package to standardize the specified data column (using mean function and SD function), and calculates the grouping mean of the standardized target varia
学内核之三:使用GDB跟踪内核调用链
R语言使用lattice包中的bwplot函数可视化箱图(box plot)、par.settings参数自定义主题模式
sharding key type not supported
[R language data science]: cross validation and looking back
MATLAB中tiledlayout函数使用
The game goes to sea and operates globally
Can mortgage with housing exclude compulsory execution
docker-compose公网部署redis哨兵模式
R language ggplot2 visualization: gganimate package creates animated graph (GIF) and uses anim_ The save function saves the GIF visual animation
基于51单片机的超声波测距仪
Why should Base64 encoding be used for image transmission
sql优化之查询优化器
Mongodb commonly used 28 query statements (forward)