当前位置:网站首页>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;
}
}
边栏推荐
- Fast parsing intranet penetration helps enterprises quickly achieve collaborative office
- IT转测试岗,从迷茫到坚定我究竟付出了什么?
- URLs and URIs
- Summer challenge brings you to play harmoniyos multi terminal piano performance
- Detailed explanation of openharmony resource management
- 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
- Five papers recommended for the new development of convolutional neural network in deep learning
- 使用快解析搭建自己的minecraft服务器
- 同事的接口文档我每次看着就头大,毛病多多。。。
- Summary of week 22-07-02
猜你喜欢
2022.07.03(LC_6108_解密消息)
How to avoid arc generation—— Aafd fault arc detector solves the problem for you
Réseau graphique: Qu'est - ce que le Protocole d'équilibrage de charge de passerelle glbp?
URL和URI
【雅思阅读】王希伟阅读P4(matching1)
Hash table, hash function, bloom filter, consistency hash
Using fast parsing intranet penetration to realize zero cost self built website
Every time I look at the interface documents of my colleagues, I get confused and have a lot of problems...
Application of multi loop instrument in base station "switching to direct"
abc 258 G - Triangle(bitset)
随机推荐
[IELTS reading] Wang Xiwei reading P3 (heading)
How many triangles are there in the golden K-line diagram?
Upload avatar on uniapp
如何用快解析自制IoT云平台
Summer challenge brings you to play harmoniyos multi terminal piano performance
如果炒股开华泰证券的户,在网上开户安全吗?
uniapp微信小程序拿来即用的瀑布流布局demo2(方法二)(复制粘贴即可使用,无需做其他处理)
ORB(Oriented FAST and Rotated BRIEF)
Learning of basic amplification circuit
Nine Qi single chip microcomputer ny8b062d single key control four LED States
Huawei employs data management experts with an annual salary of 2million! The 100 billion market behind it deserves attention
Meet ThreadPoolExecutor
2022.07.03(LC_6111_统计放置房子的方式数)
The input of uniapp is invalid except for numbers
js如何实现数组转树
巩固表达式C# 案例简单变量运算
Detailed explanation of openharmony resource management
Go pit - no required module provides Package: go. Mod file not found in current directory or any parent
圖解網絡:什麼是網關負載均衡協議GLBP?
P4281 [ahoi2008] emergency assembly / gathering (LCA)