当前位置:网站首页>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;
}
}
边栏推荐
- Summer challenge brings you to play harmoniyos multi terminal piano performance
- 用快解析内网穿透实现零成本自建网站
- PMP certificate renewal process
- 同事的接口文档我每次看着就头大,毛病多多。。。
- 雅思考试流程、需要具体注意些什么、怎么复习?
- [论文阅读] CarveMix: A Simple Data Augmentation Method for Brain Lesion Segmentation
- Best practice case of enterprise digital transformation: introduction and reference of cloud based digital platform system security measures
- uniapp微信小程序拿来即用的瀑布流布局demo2(方法二)(复制粘贴即可使用,无需做其他处理)
- 业务实现-日志写到同一个行数据里面
- 取得PMP证书需要多长时间?
猜你喜欢
使用快解析搭建自己的minecraft服务器
S32 design studio for arm 2.2 quick start
P3304 [sdoi2013] diameter (diameter of tree)
Using fast parsing intranet penetration to realize zero cost self built website
js如何实现数组转树
Data on the number of functional divisions of national wetland parks in Qinghai Province, data on the distribution of wetlands and marshes across the country, and natural reserves in provinces, cities
「运维有小邓」域密码策略强化器
He worked as a foreign lead and paid off all the housing loans in a year
[paper reading] cavemix: a simple data augmentation method for brain vision segmentation
In June, the list of winners of "Moli original author program" was announced! Invite you to talk about the domestic database
随机推荐
ECCV 2022 | Tencent Youtu proposed disco: the effect of saving small models in self supervised learning
go踩坑——no required module provides package : go.mod file not found in current directory or any parent
人脸识别5- insight-face-paddle-代码实战笔记
[JS] - [sort related] - Notes
The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!
如何在外地外网电脑远程公司项目?
[kotlin] the third day
P4408 [NOI2003] 逃学的小孩(树的直径)
Advanced template
Netcore3.1 JSON web token Middleware
香港珠宝大亨,22亿“抄底”佐丹奴
[Peking University] tensorflow2.0-1-opening
Go step on the pit - no required module provides package: go mod file not found in current directory or any parent
Significance of acrel EMS integrated energy efficiency platform in campus construction
P4281 [AHOI2008]紧急集合 / 聚会(LCA)
JS convert pseudo array to array
JS 将伪数组转换成数组
海思3559万能平台搭建:YUV422的踩坑记录
取得PMP證書需要多長時間?
Hologres Query管理及超时处理