当前位置:网站首页>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]表示的是什么东西
怎么状态转移
边栏推荐
- Understand chisel language thoroughly 06. Chisel Foundation (III) -- registers and counters
- Install and use MAC redis, connect to remote server redis
- R language ggplot2 visualization: gganimate package creates animated graph (GIF) and uses anim_ The save function saves the GIF visual animation
- Understand chisel language thoroughly 11. Chisel project construction, operation and test (III) -- scalatest of chisel test
- Rich text editing: wangeditor tutorial
- nowcoder重排链表
- Product identification of intelligent retail cabinet based on paddlex
- LifeCycle
- Excel quickly merges multiple rows of data
- 实时数据仓库
猜你喜欢
Incremental ternary subsequence [greedy training]
去除重复字母[贪心+单调栈(用数组+len来维持单调序列)]
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
Rich text editing: wangeditor tutorial
[FAQ] Huawei Account Service Error Report 907135701 Common reasons Summary and Solutions
92.(cesium篇)cesium楼栋分层
Remove duplicate letters [greedy + monotonic stack (maintain monotonic sequence with array +len)]
Oppo find N2 product form first exposure: supplement all short boards
Excel quickly merges multiple rows of data
ML之shap:基于boston波士顿房价回归预测数据集利用shap值对XGBoost模型实现可解释性案例
随机推荐
【FAQ】華為帳號服務報錯 907135701的常見原因總結和解决方法
Incremental ternary subsequence [greedy training]
数据仓库面试问题准备
Ruiji takeout notes
RK1126平台OSD的实现支持颜色半透明度多通道支持中文
【MySQL从入门到精通】【高级篇】(五)MySQL的SQL语句执行流程
IP lab monthly resumption · issue 5
按照功能对Boost库进行分类
MATLAB中tiledlayout函数使用
Ml: introduction, principle, use method and detailed introduction of classic cases of snap value
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
Install and use MAC redis, connect to remote server redis
2022游戏出海实用发行策略
sql优化之查询优化器
gin集成支付宝支付
ML:SHAP值的简介、原理、使用方法、经典案例之详细攻略
Leetcode T48:旋转图像
Can mortgage with housing exclude compulsory execution
Migration from go vendor project to mod project
R语言使用dplyr包的group_by函数和summarise函数基于分组变量计算目标变量的均值、标准差