当前位置:网站首页>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]表示的是什么东西
怎么状态转移
边栏推荐
- 测试流程整理(2)
- Oppo find N2 product form first exposure: supplement all short boards
- Understand chisel language thoroughly 12. Chisel project construction, operation and testing (IV) -- chisel test of chisel test
- Incremental ternary subsequence [greedy training]
- R语言使用dplyr包的group_by函数和summarise函数基于分组变量计算目标变量的均值、标准差
- Mask wearing detection based on yolov1
- sql优化之查询优化器
- opencv3.2 和opencv2.4安装
- Deming Lee listed on Shenzhen Stock Exchange: the market value is 3.1 billion, which is the husband and wife of Li Hu and Tian Hua
- LiveData
猜你喜欢
商業智能BI財務分析,狹義的財務分析和廣義的財務分析有何不同?
Install MySQL
瑞吉外卖笔记
Unity shader learning (3) try to draw a circle
基于51单片机的超声波测距仪
Test process arrangement (3)
Hardware Basics - diode Basics
迅为IMX6Q开发板QT系统移植tinyplay
Haobo medical sprint technology innovation board: annual revenue of 260million Yonggang and Shen Zhiqun are the actual controllers
Understand chisel language thoroughly 05. Chisel Foundation (II) -- combinational circuits and operators
随机推荐
redis 日常笔记
【信息检索】链接分析
Map of mL: Based on Boston house price regression prediction data set, an interpretable case is realized by using the map value to the LIR linear regression model
商業智能BI財務分析,狹義的財務分析和廣義的財務分析有何不同?
LiveData
Idea shortcut keys
失败率高达80%,企业数字化转型路上有哪些挑战?
R语言使用dplyr包的group_by函数和summarise函数基于分组变量计算目标变量的均值、标准差
Detailed index of MySQL
2022游戏出海实用发行策略
基于PaddleX的智能零售柜商品识别
Haobo medical sprint technology innovation board: annual revenue of 260million Yonggang and Shen Zhiqun are the actual controllers
数据中台概念
Ruichengxin micro sprint technology innovation board: annual revenue of 367million, proposed to raise 1.3 billion, Datang Telecom is a shareholder
Common content type correspondence table
LiveData
Unity Shader学习(三)试着绘制一个圆
卷积神经网络经典论文集合(深度学习分类篇)
R language uses the DOTPLOT function of epidisplay package to visualize the frequency of data points in different intervals in the form of point graph, and uses the by parameter to specify the groupin
一种架构来完成所有任务—Transformer架构正在以一己之力统一AI江湖