当前位置:网站首页>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]表示的是什么东西
怎么状态转移
边栏推荐
- Incremental ternary subsequence [greedy training]
- 92.(cesium篇)cesium楼栋分层
- 2022 practice questions and mock exams for the main principals of hazardous chemical business units
- 卷积神经网络经典论文集合(深度学习分类篇)
- Haobo medical sprint technology innovation board: annual revenue of 260million Yonggang and Shen Zhiqun are the actual controllers
- China Post technology rushes to the scientific innovation board: the annual revenue is 2.058 billion, and the postal group is the major shareholder
- Use of arouter
- Unity Shader学习(三)试着绘制一个圆
- LifeCycle
- Data warehouse interview question preparation
猜你喜欢

vscode 常用插件汇总

Unity shader learning (3) try to draw a circle

使用CLion编译OGLPG-9th-Edition源码

TestSuite and testrunner in unittest

Excel quickly merges multiple rows of data

聊聊保证线程安全的 10 个小技巧

Ruichengxin micro sprint technology innovation board: annual revenue of 367million, proposed to raise 1.3 billion, Datang Telecom is a shareholder

软件测试之测试评估

sharding key type not supported

Intelligence d'affaires bi analyse financière, analyse financière au sens étroit et analyse financière au sens large sont - ils différents?
随机推荐
AI与生命科学
富文本编辑:wangEditor使用教程
Ruiji takeout notes
IP lab monthly resumption · issue 5
Vscode common plug-ins summary
R语言ggplot2可视化:gganimate包创建动画图(gif)、使用anim_save函数保存gif可视化动图
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
迅为IMX6Q开发板QT系统移植tinyplay
Install and use MAC redis, connect to remote server redis
瑞吉外卖笔记
Excel快速合并多行数据
Learning projects are self-made, and growth opportunities are self created
Leetcode T49: 字母异位词分组
sql优化之explain
Learn kernel 3: use GDB to track the kernel call chain
利用Shap值进行异常值检测
92.(cesium篇)cesium楼栋分层
ARouter的使用
学内核之三:使用GDB跟踪内核调用链
海外游戏代投需要注意的