当前位置:网站首页>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]表示的是什么东西
怎么状态转移
边栏推荐
- Install MySQL
- 数据仓库面试问题准备
- sql优化之查询优化器
- opencv3.2 和opencv2.4安装
- 【Matlab】conv、filter、conv2、filter2和imfilter卷积函数总结
- MATLAB中tiledlayout函数使用
- Apple 5g chip research and development failure: continue to rely on Qualcomm, but also worry about being prosecuted?
- Matters needing attention in overseas game Investment Agency
- What is the real meaning and purpose of doing things, and what do you really want
- Golang uses JSON unmarshal number to interface{} number to become float64 type (turn)
猜你喜欢

92.(cesium篇)cesium楼栋分层

10.(地图数据篇)离线地形数据处理(供Cesium使用)

Innovation and development of independent industrial software

商業智能BI財務分析,狹義的財務分析和廣義的財務分析有何不同?

Excel quickly merges multiple rows of data
![Remove duplicate letters [greedy + monotonic stack (maintain monotonic sequence with array +len)]](/img/af/a1dcba6f45eb4ccc668cd04a662e9c.png)
Remove duplicate letters [greedy + monotonic stack (maintain monotonic sequence with array +len)]

Detailed index of MySQL

软件测试之测试评估

Xcode 异常图片导致ipa包增大问题

Mask wearing detection based on yolov1
随机推荐
R language ggplot2 visualization: gganimate package creates dynamic line graph animation (GIF) and uses transition_ The reveal function displays data step by step along a given dimension in the animat
MATLAB中tiledlayout函数使用
flink sql-client.sh 使用教程
按照功能对Boost库进行分类
Understand chisel language thoroughly 03. Write to the developer of Verilog to chisel (you can also see it without Verilog Foundation)
Understand chisel language thoroughly 10. Chisel project construction, operation and testing (II) -- Verilog code generation in chisel & chisel development process
Test process arrangement (3)
去除重複字母[貪心+單調棧(用數組+len來維持單調序列)]
Data warehouse interview question preparation
Detailed index of MySQL
基于51单片机的超声波测距仪
LiveData
sql优化之查询优化器
gin集成支付宝支付
如何游戏出海代运营、游戏出海代投
【信息检索】链接分析
Excel quickly merges multiple rows of data
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
TestSuite and testrunner in unittest
Haobo medical sprint technology innovation board: annual revenue of 260million Yonggang and Shen Zhiqun are the actual controllers