当前位置:网站首页>2022.07.03 (LC 6109 number of people who know secrets)
2022.07.03 (LC 6109 number of people who know secrets)
2022-07-05 00:14:00 【Leeli9316】
Method : Dynamic programming
class Solution {
public int peopleAwareOfSecret(int n, int delay, int forget) {
int MOD = 1000000007;
// state :f[i] It means the first one i Tianxin knows the number of Secrets
int[] f = new int[n + 1];
f[1] = 1;
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= i; j++) {
// In the i God , Only (i - forget, i - delay] New people who know the secret in this range will tell others
// Be careful i - forget + 1 and i - delay Maybe more than [1, n] The scope of the , We need to deal with the boundary
if (j > i - forget && j <= i - delay) {
f[i] = (f[i] + f[j]) % MOD;
}
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
// The answer is in No n Heaven has not forgotten the sum of the secret numbers
if (i + forget > n) {
ans = (ans + f[i]) % MOD;
}
}
return ans;
}
}
边栏推荐
- Mit-6.824-lab4b-2022 (10000 word idea explanation - code construction)
- js如何实现数组转树
- P4281 [AHOI2008]紧急集合 / 聚会(LCA)
- In the enterprise, win10 turns on BitLocker to lock the disk, how to back up the system, how to recover when the system has problems, and how to recover quickly while taking into account system securi
- [IELTS reading] Wang Xiwei reading P4 (matching1)
- 2022.07.03(LC_6109_知道秘密的人数)
- 海思3559万能平台搭建:YUV422的踩坑记录
- [monitoring] ZABBIX
- 华为200万年薪聘请数据治理专家!背后的千亿市场值得关注
- ORB(Oriented FAST and Rotated BRIEF)
猜你喜欢
基于三维gis平台的消防系统运用
如何在外地外网电脑远程公司项目?
ORB(Oriented FAST and Rotated BRIEF)
Hisilicon 3559 universal platform construction: YUV422 pit stepping record
IT转测试岗,从迷茫到坚定我究竟付出了什么?
人脸识别5- insight-face-paddle-代码实战笔记
abc 258 G - Triangle(bitset)
【路径规划】RRT增加动力模型进行轨迹规划
Using fast parsing intranet penetration to realize zero cost self built website
机器人强化学习——Learning Synergies between Pushing and Grasping with Self-supervised DRL (2018)
随机推荐
Mit-6.824-lab4b-2022 (10000 word idea explanation - code construction)
uniapp微信小程序拿来即用的瀑布流布局demo2(方法二)(复制粘贴即可使用,无需做其他处理)
The pit of sizeof operator in C language
[path planning] RRT adds dynamic model for trajectory planning
人生无常,大肠包小肠, 这次真的可以回家看媳妇去了。。。
lambda表达式
Life is changeable, and the large intestine covers the small intestine. This time, I can really go home to see my daughter-in-law...
华为200万年薪聘请数据治理专家!背后的千亿市场值得关注
lambda expressions
Significance of acrel EMS integrated energy efficiency platform in campus construction
[IELTS reading] Wang Xiwei reading P3 (heading)
How many triangles are there in the golden K-line diagram?
跨域请求
Réseau graphique: Qu'est - ce que le Protocole d'équilibrage de charge de passerelle glbp?
Go step on the pit - no required module provides package: go mod file not found in current directory or any parent
Acrel-EMS综合能效平台在校园建设的意义
Skills in analyzing the trend chart of London Silver
ORB(Oriented FAST and Rotated BRIEF)
Netcore3.1 JSON web token Middleware
青海省国家湿地公园功能区划数数据、全国湿地沼泽分布数据、全国省市县自然保护区