当前位置:网站首页>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;
}
}边栏推荐
- Specification for fs4061a boost 8.4v charging IC chip and fs4061b boost 12.6V charging IC chip datasheet
- 他做国外LEAD,用了一年时间,把所有房贷都还清了
- Every time I look at the interface documents of my colleagues, I get confused and have a lot of problems...
- Advanced template
- Introduction to ACM combination counting
- AcWing164. 可达性统计(拓扑排序+bitset)
- 端口映射和端口转发区别是什么
- 快解析——好用的内网安全软件
- uniapp 除了数字,其他输入无效
- 45 year old professor, she threw two super unicorns
猜你喜欢

Consolidated expression C case simple variable operation

城市轨道交通站应急照明疏散指示系统设计

The waterfall flow layout demo2 (method 2) used by the uniapp wechat applet (copy and paste can be used without other processing)

He worked as a foreign lead and paid off all the housing loans in a year

abc 258 G - Triangle(bitset)

Face recognition 5- insight face padding code practice notes

初识ROS

Fast analysis -- easy to use intranet security software

【路径规划】RRT增加动力模型进行轨迹规划

Parsing of XML
随机推荐
[paper reading] Tun det: a novel network for meridian ultra sound nodule detection
同事的接口文档我每次看着就头大,毛病多多。。。
Skills in analyzing the trend chart of London Silver
[论文阅读] TUN-Det: A Novel Network for Thyroid Ultrasound Nodule Detection
[IELTS reading] Wang Xiwei reads P4 (matching2 paragraph information matching question [difficult])
PaddleOCR教程
Acrel-EMS综合能效平台在校园建设的意义
人脸识别5- insight-face-paddle-代码实战笔记
【雅思阅读】王希伟阅读P3(Heading)
Is it safe to open an account in the College of Finance and economics? How to open an account?
abc 258 G - Triangle(bitset)
快解析——好用的内网安全软件
[JS] - [dynamic planning] - Notes
Summer challenge brings you to play harmoniyos multi terminal piano performance
如何用快解析自制IoT云平台
Hologres Query管理及超时处理
Upload avatar on uniapp
go踩坑——no required module provides package : go.mod file not found in current directory or any parent
打新债开户注册安全吗?有没有风险的?靠谱吗?
【路径规划】RRT增加动力模型进行轨迹规划