当前位置:网站首页>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;
}
}
边栏推荐
- 多回路仪表在基站“转改直”方面的应用
- 【报错】 “TypeError: Cannot read properties of undefined (reading ‘split‘)“
- Specification for fs4061a boost 8.4v charging IC chip and fs4061b boost 12.6V charging IC chip datasheet
- Microservice
- Date time type and format in MySQL
- Summary of week 22-07-02
- C语言中sizeof操作符的坑
- IELTS examination process, what to pay attention to and how to review?
- [IELTS reading] Wang Xiwei reading P3 (heading)
- abc 258 G - Triangle(bitset)
猜你喜欢
青海省国家湿地公园功能区划数数据、全国湿地沼泽分布数据、全国省市县自然保护区
IT转测试岗,从迷茫到坚定我究竟付出了什么?
ECCV 2022 | Tencent Youtu proposed disco: the effect of saving small models in self supervised learning
巩固表达式C# 案例简单变量运算
He worked as a foreign lead and paid off all the housing loans in a year
Design of emergency lighting evacuation indication system for urban rail transit station
如何报考PMP项目管理认证考试?
Combien de temps faut - il pour obtenir un certificat PMP?
It's too convenient. You can complete the code release and approval by nailing it!
The input of uniapp is invalid except for numbers
随机推荐
Ap8022 switching power supply small household appliances ACDC chip offline switching power supply IC
Hong Kong Jewelry tycoon, 2.2 billion "bargain hunting" Giordano
[kotlin] the third day
Hologres Query管理及超时处理
JS how to realize array to tree
如果炒股开华泰证券的户,在网上开户安全吗?
GDB常用命令
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
45岁教授,她投出2个超级独角兽
PMP certificate renewal process
ORB(Oriented FAST and Rotated BRIEF)
Expand your kubecl function
22-07-02周总结
Using the uniapp rich text editor
Illustrated network: what is gateway load balancing protocol GLBP?
Life is changeable, and the large intestine covers the small intestine. This time, I can really go home to see my daughter-in-law...
js如何实现数组转树
45 year old professor, she threw two super unicorns
积分商城游戏设置的基本要点
ICML 2022 | 3dlinker: e (3) equal variation self encoder for molecular link design