当前位置:网站首页>leetcode:6109. Number of people who know the secret [definition of DP]
leetcode:6109. Number of people who know the secret [definition of DP]
2022-07-04 14:27:00 【White speed Dragon King's review】
analysis
dp[i] It is defined as the first i Who just knows the secret
then dp[i] Is equal to dp[i - delay] To dp[i - forget] All and ( Specifically +1-1debug Besides, )
And then at the end of the day forget Before dp Sum of
ac code
class Solution:
def peopleAwareOfSecret(self, n: int, delay: int, forget: int) -> int:
MOD = 10 ** 9 + 7
ans = 0
# dp[i] Express The first i How many people just know the secret
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
summary
dp[i] What does it mean
How to state transition
边栏推荐
- 基于51单片机的超声波测距仪
- R language uses the mutation function of dplyr package to standardize the specified data column (using mean function and SD function), and calculates the grouping mean of the standardized target varia
- Leetcode 61: rotating linked list
- Real time data warehouse
- R语言ggplot2可视化:gganimate包创建动态折线图动画(gif)、使用transition_reveal函数在动画中沿给定维度逐步显示数据
- Leetcode T48: rotating images
- 【信息检索】链接分析
- ViewModel 初体验
- Leetcode T49: 字母异位词分组
- Migration from go vendor project to mod project
猜你喜欢
The implementation of OSD on rk1126 platform supports color translucency and multi-channel support for Chinese
sql优化之查询优化器
gin集成支付宝支付
Count the running time of PHP program and set the maximum running time of PHP
[MySQL from introduction to proficiency] [advanced chapter] (V) SQL statement execution process of MySQL
按照功能对Boost库进行分类
一文概览2D人体姿态估计
使用CLion编译OGLPG-9th-Edition源码
STM32F1与STM32CubeIDE编程实例-MAX7219驱动8位7段数码管(基于GPIO)
失败率高达80%,企业数字化转型路上有哪些挑战?
随机推荐
一文概览2D人体姿态估计
GCC [6] - 4 stages of compilation
数据中台概念
R语言使用dplyr包的mutate函数对指定数据列进行标准化处理(使用mean函数和sd函数)并基于分组变量计算标准化后的目标变量的分组均值
The implementation of OSD on rk1126 platform supports color translucency and multi-channel support for Chinese
【云原生】我怎么会和这个数据库杠上了?
【信息检索】分类和聚类的实验
SqlServer函数,存储过程的创建和使用
数据埋点的一些问题和想法
File creation, writing, reading, deletion (transfer) in go language
Leetcode 61: rotating linked list
Install and use MAC redis, connect to remote server redis
MySQL的存储过程练习题
关于miui12.5 红米k20pro用au或者povo2出现问题的解决办法
No servers available for service: xxxx
卷积神经网络经典论文集合(深度学习分类篇)
数据仓库面试问题准备
Leetcode 61: 旋转链表
Use of arouter
vscode 常用插件汇总