当前位置:网站首页>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;
}
}边栏推荐
- 如果炒股开华泰证券的户,在网上开户安全吗?
- lambda表达式
- Ap8022 switching power supply small household appliances ACDC chip offline switching power supply IC
- 如何用快解析自制IoT云平台
- TS快速入门-函数
- 雅思考试流程、需要具体注意些什么、怎么复习?
- Get to know ROS for the first time
- Summer challenge brings you to play harmoniyos multi terminal piano performance
- PermissionError: [Errno 13] Permission denied: ‘data. csv‘
- Paddleocr tutorial
猜你喜欢

How to effectively monitor the DC column head cabinet

快解析——好用的内网安全软件

In June, the list of winners of "Moli original author program" was announced! Invite you to talk about the domestic database

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

The input of uniapp is invalid except for numbers

IELTS examination process, what to pay attention to and how to review?

用快解析内网穿透实现零成本自建网站

人脸识别5- insight-face-paddle-代码实战笔记

初识ROS

XML的解析
随机推荐
Application of multi loop instrument in base station "switching to direct"
Expand your kubecl function
Chinese verification of JS regular expressions (turn)
Meet ThreadPoolExecutor
Réseau graphique: Qu'est - ce que le Protocole d'équilibrage de charge de passerelle glbp?
P4281 [ahoi2008] emergency assembly / gathering (LCA)
快解析内网穿透帮助企业快速实现协同办公
打新债开户注册安全吗?有没有风险的?靠谱吗?
企业应用业务场景,功能添加和修改C#源码
P4281 [AHOI2008]紧急集合 / 聚会(LCA)
巩固表达式C# 案例简单变量运算
Fast parsing intranet penetration helps enterprises quickly achieve collaborative office
The waterfall flow layout demo2 (method 2) used by the uniapp wechat applet (copy and paste can be used without other processing)
Go pit - no required module provides Package: go. Mod file not found in current directory or any parent
Parsing of XML
[IELTS reading] Wang Xiwei reading P3 (heading)
Using fast parsing intranet penetration to realize zero cost self built website
Go step on the pit - no required module provides package: go mod file not found in current directory or any parent
How to effectively monitor the DC column head cabinet
How many triangles are there in the golden K-line diagram?