当前位置:网站首页>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]表示的是什么东西
怎么状态转移
边栏推荐
- R语言ggplot2可视化:gganimate包创建动态折线图动画(gif)、使用transition_reveal函数在动画中沿给定维度逐步显示数据
- TestSuite and testrunner in unittest
- LifeCycle
- redis 日常笔记
- The font of markdown grammar is marked in red
- Understand chisel language thoroughly 05. Chisel Foundation (II) -- combinational circuits and operators
- R语言使用dplyr包的group_by函数和summarise函数基于分组变量计算目标变量的均值、标准差
- vscode 常用插件汇总
- [matlab] summary of conv, filter, conv2, Filter2 and imfilter convolution functions
- 【FAQ】華為帳號服務報錯 907135701的常見原因總結和解决方法
猜你喜欢
学内核之三:使用GDB跟踪内核调用链
Test evaluation of software testing
基于51单片机的超声波测距仪
Product identification of intelligent retail cabinet based on paddlex
Install MySQL
sql优化之explain
Mask wearing detection based on yolov1
Understand chisel language thoroughly 12. Chisel project construction, operation and testing (IV) -- chisel test of chisel test
Ruichengxin micro sprint technology innovation board: annual revenue of 367million, proposed to raise 1.3 billion, Datang Telecom is a shareholder
聊聊保证线程安全的 10 个小技巧
随机推荐
NowCoder 反转链表
Excel快速合并多行数据
Ml: introduction, principle, use method and detailed introduction of classic cases of snap value
实时数据仓库
Huahao Zhongtian rushes to the scientific and Technological Innovation Board: the annual loss is 280million, and it is proposed to raise 1.5 billion. Beida pharmaceutical is a shareholder
[antd] how to set antd in form There is input in item Get input when gourp Value of each input of gourp
2022 practice questions and mock exams for the main principals of hazardous chemical business units
ML之shap:基于boston波士顿房价回归预测数据集利用shap值对XGBoost模型实现可解释性案例
基于51单片机的超声波测距仪
Yingshi Ruida rushes to the scientific and Technological Innovation Board: the annual revenue is 450million and the proposed fund-raising is 979million
[R language data science]: cross validation and looking back
C# wpf 实现截屏框实时截屏功能
Understand chisel language thoroughly 05. Chisel Foundation (II) -- combinational circuits and operators
flink sql-client.sh 使用教程
vscode 常用插件汇总
学内核之三:使用GDB跟踪内核调用链
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
第十七章 进程内存
Mask wearing detection based on yolov1
奇妙秘境 码蹄集