当前位置:网站首页>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]表示的是什么东西
怎么状态转移
边栏推荐
- Mongodb commonly used 28 query statements (forward)
- 2022 practice questions and mock exams for the main principals of hazardous chemical business units
- 利用Shap值进行异常值检测
- 聊聊保证线程安全的 10 个小技巧
- 软件测试之测试评估
- LiveData
- Understand chisel language thoroughly 04. Chisel Foundation (I) - signal type and constant
- Leetcode T48:旋转图像
- vscode 常用插件汇总
- 基于51单片机的超声波测距仪
猜你喜欢
随机推荐
Gorm read / write separation (rotation)
Ws2818m is packaged in cpc8. It is a special circuit for three channel LED drive control. External IC full-color double signal 5v32 lamp programmable LED lamp with outdoor engineering
[antd] how to set antd in form There is input in item Get input when gourp Value of each input of gourp
MySQL的触发器
Test evaluation of software testing
LiveData
Incremental ternary subsequence [greedy training]
Can mortgage with housing exclude compulsory execution
MATLAB中tiledlayout函数使用
卷积神经网络经典论文集合(深度学习分类篇)
Understand chisel language thoroughly 03. Write to the developer of Verilog to chisel (you can also see it without Verilog Foundation)
第十七章 进程内存
How to operate and invest games on behalf of others at sea
Understand chisel language thoroughly 05. Chisel Foundation (II) -- combinational circuits and operators
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
2022 game going to sea practical release strategy
Understand chisel language thoroughly 11. Chisel project construction, operation and test (III) -- scalatest of chisel test
数据埋点的一些问题和想法
Excel quickly merges multiple rows of data
C# wpf 实现截屏框实时截屏功能