当前位置:网站首页>LeetCode 6109. Number of people who know the secret
LeetCode 6109. Number of people who know the secret
2022-07-05 18:19:00 【HumbleFool】
LeetCode 6109. Number of people who know the secret
linear DP + Prefixes and optimizations
/* f[i][j] Before presentation i God , Remember the secret j Number of days j == 1: Altogether delay <= j < forget Number f[i][j] = f[i - 1][delay] + f[i - 1][delay + 1] ... f[i - 1][forget - 1]; Here we find the continuous sum , violence n^3, Will timeout , Prefixes and optimizations f[i][j] = f[i - 1][forget - 1] - f[i - 1][delay - 1]; j > 1: f[i][j] = f[i - 1][j - 1]; f[i][j] = f[i - 1][j - 1] - f[i - 1][j - 2] */
const int N = 1010, MOD = 1e9 + 7;
class Solution {
public:
int f[N][N];
int peopleAwareOfSecret(int n, int delay, int forget) {
for(int i = 1; i <= forget; i ++) f[1][i] = 1;
for(int i = 2; i <= n; i ++)
{
for(int j = 1; j <= forget; j ++)
{
if(j > 1) f[i][j] = (f[i - 1][j - 1] - f[i - 1][j - 2]) % MOD;
else if(j == 1) f[i][j] = (f[i - 1][forget - 1] - f[i - 1][delay - 1]) % MOD;
f[i][j] = (f[i][j] + f[i][j - 1]) % MOD;
}
}
return (f[n][forget] + MOD) % MOD;
}
};
边栏推荐
- Fix vulnerability - mysql, ES
- IDC report: Tencent cloud database ranks top 2 in the relational database market!
- 【PaddlePaddle】 PaddleDetection 人脸识别 自定义数据集
- Sophon CE社区版上线,免费Get轻量易用、高效智能的数据分析工具
- How to obtain the coordinates of the aircraft passing through both ends of the radar
- Nacos distributed transactions Seata * * install JDK on Linux, mysql5.7 start Nacos configure ideal call interface coordination (nanny level detail tutorial)
- Wu Enda team 2022 machine learning course, coming
- Failed to virtualize table with JMeter
- Sophon Base 3.1 推出MLOps功能,为企业AI能力运营插上翅膀
- 记录Pytorch中的eval()和no_grad()
猜你喜欢
Find the first k small element select_ k
吴恩达团队2022机器学习课程,来啦
ConvMAE(2022-05)
图扑软件数字孪生 | 基于 BIM 技术的可视化管理系统
记一次使用Windbg分析内存“泄漏”的案例
ISPRS2022/雲檢測:Cloud detection with boundary nets基於邊界網的雲檢測
Thoroughly understand why network i/o is blocked?
About Statistical Power(统计功效)
Tencent music launched its new product "quyimai", which provides music commercial copyright authorization
如何获取飞机穿过雷达两端的坐标
随机推荐
Use of print function in MATLAB
华夏基金:基金行业数字化转型实践成果分享
Multithreading (I) processes and threads
[QNX Hypervisor 2.2用户手册]6.3.2 配置VM
[TestLink] testlink1.9.18 solutions to common problems
生词生词生词生词[2]
最大人工岛[如何让一个连通分量的所有节点都记录总节点数?+给连通分量编号]
Introduction to VC programming on "suggestions collection"
图像分类,看我就够啦!
使用Jmeter虚拟化table失败
Tencent music launched its new product "quyimai", which provides music commercial copyright authorization
《2022中国信创生态市场研究及选型评估报告》发布 华云数据入选信创IT基础设施主流厂商!
[JMeter] advanced writing method of JMeter script: all variables, parameters (parameters can be configured by Jenkins), functions, etc. in the interface automation script realize the complete business
Clickhouse (03) how to install and deploy Clickhouse
IDC report: Tencent cloud database ranks top 2 in the relational database market!
Xiaobai getting started with NAS - quick building private cloud tutorial series (I) [easy to understand]
To solve the stubborn problem of Lake + warehouse hybrid architecture, xinghuan Technology launched an independent and controllable cloud native Lake warehouse integrated platform
Matlab built-in function how different colors, matlab subsection function different colors drawing
Isprs2022 / Cloud Detection: Cloud Detection with Boundary nets Boundary Networks Based Cloud Detection
Introduction to the development function of Hanlin Youshang system of Hansheng Youpin app