当前位置:网站首页>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;
}
}边栏推荐
- Is the account opening link of Huatai Securities with low commission safe?
- Power operation and maintenance cloud platform: open the new mode of "unattended and few people on duty" of power system
- 快解析——好用的内网安全软件
- Go pit - no required module provides Package: go. Mod file not found in current directory or any parent
- JS 将伪数组转换成数组
- 45 year old professor, she threw two super unicorns
- How to effectively monitor the DC column head cabinet
- [论文阅读] CarveMix: A Simple Data Augmentation Method for Brain Lesion Segmentation
- Go step on the pit - no required module provides package: go mod file not found in current directory or any parent
- Fast analysis -- easy to use intranet security software
猜你喜欢

A new method for analyzing the trend chart of London Silver

Netcore3.1 JSON web token Middleware

Face recognition 5- insight face padding code practice notes

IT转测试岗,从迷茫到坚定我究竟付出了什么?

Fs8b711s14 electric wine bottle opener MCU IC scheme development special integrated IC

圖解網絡:什麼是網關負載均衡協議GLBP?

Some basic functions of enterprise projects are developed, and important things are saved to online first a

Tester's algorithm interview question - find mode

巩固表达式C# 案例简单变量运算

如何报考PMP项目管理认证考试?
随机推荐
Is it safe to open an account in the College of Finance and economics? How to open an account?
同事的接口文档我每次看着就头大,毛病多多。。。
Paddleocr tutorial
Introduction to ACM combination counting
Jar batch management gadget
Skills in analyzing the trend chart of London Silver
【北京大学】Tensorflow2.0-1-开篇
In June, the list of winners of "Moli original author program" was announced! Invite you to talk about the domestic database
How long does it take to obtain a PMP certificate?
业务实现-日志写到同一个行数据里面
【雅思阅读】王希伟阅读P3(Heading)
The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!
基于三维gis平台的消防系统运用
Meet ThreadPoolExecutor
Specification for fs4061a boost 8.4v charging IC chip and fs4061b boost 12.6V charging IC chip datasheet
uniapp上传头像
[paper reading] Tun det: a novel network for meridian ultra sound nodule detection
Hong Kong Jewelry tycoon, 2.2 billion "bargain hunting" Giordano
企业应用业务场景,功能添加和修改C#源码
[IELTS reading] Wang Xiwei reading P4 (matching1)