当前位置:网站首页>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;
}
}边栏推荐
猜你喜欢

青海省国家湿地公园功能区划数数据、全国湿地沼泽分布数据、全国省市县自然保护区

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

Specification for fs4061a boost 8.4v charging IC chip and fs4061b boost 12.6V charging IC chip datasheet

uniapp微信小程序拿来即用的瀑布流布局demo2(方法二)(复制粘贴即可使用,无需做其他处理)

使用快解析搭建自己的minecraft服务器

"Xiaodeng" domain password policy enhancer in operation and maintenance

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

Build your own minecraft server with fast parsing

他做国外LEAD,用了一年时间,把所有房贷都还清了

Application of fire fighting system based on 3D GIS platform
随机推荐
如何将自己的代码作品快速存证,已更好的保护自己劳动成果
S32 design studio for arm 2.2 quick start
Introduction to ACM combination counting
取得PMP證書需要多長時間?
45岁教授,她投出2个超级独角兽
Best practice case of enterprise digital transformation: introduction and reference of cloud based digital platform system security measures
Hash table, hash function, bloom filter, consistency hash
模板的进阶
[IELTS reading] Wang Xiwei reading P3 (heading)
P4408 [NOI2003] 逃学的小孩(树的直径)
初识ROS
45 year old professor, she threw two super unicorns
ICML 2022 | 3dlinker: e (3) equal variation self encoder for molecular link design
Is the account opening link of Huatai Securities with low commission safe?
【路径规划】RRT增加动力模型进行轨迹规划
go踩坑——no required module provides package : go.mod file not found in current directory or any parent
Summary of week 22-07-02
Go 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
uniapp上传头像