当前位置:网站首页>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;
}
}
边栏推荐
- 企业应用业务场景,功能添加和修改C#源码
- A new method for analyzing the trend chart of London Silver
- ORB(Oriented FAST and Rotated BRIEF)
- 《论文笔记》Multi-UAV Collaborative Monocular SLAM
- [IELTS reading] Wang Xiwei reading P4 (matching1)
- Summary of week 22-07-02
- 2022.07.03(LC_6108_解密消息)
- Acwing164. Accessibility Statistics (topological sorting +bitset)
- 【路径规划】RRT增加动力模型进行轨迹规划
- 用快解析内网穿透实现零成本自建网站
猜你喜欢
Power operation and maintenance cloud platform: open the new mode of "unattended and few people on duty" of power system
Hisilicon 3559 universal platform construction: YUV422 pit stepping record
Réseau graphique: Qu'est - ce que le Protocole d'équilibrage de charge de passerelle glbp?
快解析——好用的内网安全软件
Learning of basic amplification circuit
【雅思阅读】王希伟阅读P4(matching1)
What did I pay for it transfer to testing post from confusion to firmness?
Mit-6.824-lab4b-2022 (10000 word idea explanation - code construction)
Using the uniapp rich text editor
企业公司项目开发好一部分基础功能,重要的事保存到线上第一a
随机推荐
Hologres Query管理及超时处理
How to use fast parsing to make IOT cloud platform
PermissionError: [Errno 13] Permission denied: ‘data. csv‘
人生无常,大肠包小肠, 这次真的可以回家看媳妇去了。。。
C语言中sizeof操作符的坑
Date time type and format in MySQL
Significance of acrel EMS integrated energy efficiency platform in campus construction
Application of multi loop instrument in base station "switching to direct"
Huawei employs data management experts with an annual salary of 2million! The 100 billion market behind it deserves attention
[paper reading] cavemix: a simple data augmentation method for brain vision segmentation
Instructions for go defer
业务实现-日志写到同一个行数据里面
URL和URI
Paddleocr tutorial
The input of uniapp is invalid except for numbers
如果炒股开华泰证券的户,在网上开户安全吗?
abc 258 G - Triangle(bitset)
端口映射和端口转发区别是什么
如何将自己的代码作品快速存证,已更好的保护自己劳动成果
How many triangles are there in the golden K-line diagram?