当前位置:网站首页>2022.07.03(LC_6109_知道秘密的人数)
2022.07.03(LC_6109_知道秘密的人数)
2022-07-05 00:08:00 【Leeli9316】

方法:动态规划
class Solution {
public int peopleAwareOfSecret(int n, int delay, int forget) {
int MOD = 1000000007;
//状态:f[i]表示第i天新知道秘密的人数
int[] f = new int[n + 1];
f[1] = 1;
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= i; j++) {
//在第i天,只有(i - forget, i - delay]这个区间里新知道秘密的人才会告诉其它人
//注意i - forget + 1和 i - delay可能超出[1, n]的范围,需要处理一下边界
if (j > i - forget && j <= i - delay) {
f[i] = (f[i] + f[j]) % MOD;
}
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
//答案就是在第n天还没有忘记秘密的人数之和
if (i + forget > n) {
ans = (ans + f[i]) % MOD;
}
}
return ans;
}
}边栏推荐
- uniapp微信小程序拿来即用的瀑布流布局demo2(方法二)(复制粘贴即可使用,无需做其他处理)
- Go pit - no required module provides Package: go. Mod file not found in current directory or any parent
- 挖财学院开户安全的吗?开户怎么开?
- Acrel-EMS综合能效平台在校园建设的意义
- Significance of acrel EMS integrated energy efficiency platform in campus construction
- Fast parsing intranet penetration helps enterprises quickly achieve collaborative office
- 快解析内网穿透帮助企业快速实现协同办公
- [论文阅读] CarveMix: A Simple Data Augmentation Method for Brain Lesion Segmentation
- Paddleocr tutorial
- Consolidated expression C case simple variable operation
猜你喜欢

基本放大电路的学习
![[IELTS reading] Wang Xiwei reads P4 (matching2 paragraph information matching question [difficult])](/img/83/63296108b47eda37c19b9ff9deb5ec.png)
[IELTS reading] Wang Xiwei reads P4 (matching2 paragraph information matching question [difficult])

如何用快解析自制IoT云平台

人脸识别5- insight-face-paddle-代码实战笔记

Microservice

How many triangles are there in the golden K-line diagram?

取得PMP證書需要多長時間?

他做国外LEAD,用了一年时间,把所有房贷都还清了
![[paper reading] cavemix: a simple data augmentation method for brain vision segmentation](/img/41/eb790e7419a158e985fa503bd7dc17.png)
[paper reading] cavemix: a simple data augmentation method for brain vision segmentation

Hash table, hash function, bloom filter, consistency hash
随机推荐
How to do the project of computer remote company in foreign Internet?
【路径规划】RRT增加动力模型进行轨迹规划
华为200万年薪聘请数据治理专家!背后的千亿市场值得关注
多回路仪表在基站“转改直”方面的应用
[IELTS reading] Wang Xiwei reading P4 (matching1)
Advanced template
[论文阅读] TUN-Det: A Novel Network for Thyroid Ultrasound Nodule Detection
业务场景功能的继续修改
企业公司项目开发好一部分基础功能,重要的事保存到线上第一a
Jar batch management gadget
巩固表达式C# 案例简单变量运算
Significance of acrel EMS integrated energy efficiency platform in campus construction
Some basic functions of enterprise projects are developed, and important things are saved to online first a
积分商城游戏设置的基本要点
XML的解析
Is the account opening link of Huatai Securities with low commission safe?
[monitoring] ZABBIX
How to apply for PMP project management certification examination?
"Xiaodeng" domain password policy enhancer in operation and maintenance
如何在外地外网电脑远程公司项目?