当前位置:网站首页>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
边栏推荐
- MySQL之详解索引
- The font of markdown grammar is marked in red
- leetcode:6109. 知道秘密的人数【dp的定义】
- 流行框架:Glide的使用
- Innovation and development of independent industrial software
- nowcoder重排链表
- C# wpf 实现截屏框实时截屏功能
- File creation, writing, reading, deletion (transfer) in go language
- 富文本编辑:wangEditor使用教程
- R language dplyr package summary_ If function calculates the mean and median of all numerical data columns in dataframe data, and summarizes all numerical variables based on conditions
猜你喜欢
Data warehouse interview question preparation
测试流程整理(3)
实时数据仓库
Rich text editing: wangeditor tutorial
sql优化之explain
leetcode:6109. 知道秘密的人数【dp的定义】
【MySQL从入门到精通】【高级篇】(四)MySQL权限管理与控制
vscode 常用插件汇总
What is the difference between Bi financial analysis in a narrow sense and financial analysis in a broad sense?
Vscode common plug-ins summary
随机推荐
数据中台概念
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
Oppo find N2 product form first exposure: supplement all short boards
RK1126平台OSD的实现支持颜色半透明度多通道支持中文
Rich text editing: wangeditor tutorial
Innovation and development of independent industrial software
Visual Studio调试方式详解
R language uses dplyr package group_ The by function and the summarize function calculate the mean and standard deviation of the target variables based on the grouped variables
C# wpf 实现截屏框实时截屏功能
第十六章 字符串本地化和消息字典(二)
Supprimer les lettres dupliquées [avidité + pile monotone (maintenir la séquence monotone avec un tableau + Len)]
Digi restarts XBee Pro S2C production. Some differences need to be noted
【MySQL从入门到精通】【高级篇】(四)MySQL权限管理与控制
SqlServer函数,存储过程的创建和使用
Use of arouter
为什么图片传输要使用base64编码
gin集成支付宝支付
使用CLion编译OGLPG-9th-Edition源码
Digi XBee 3 RF: 4个协议,3种封装,10个大功能
Use of tiledlayout function in MATLAB