当前位置:网站首页>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;
}
};
边栏推荐
猜你喜欢
Vulnhub's darkhole_ two
Leetcode exercise - 206 Reverse linked list
node_ Exporter memory usage is not displayed
瀚升优品app翰林优商系统开发功能介绍
Huaxia Fund: sharing of practical achievements of digital transformation in the fund industry
About Estimation with Cross-Validation
Record eval() and no in pytoch_ grad()
Star Ring Technology launched transwarp Navier, a data element circulation platform, to help enterprises achieve secure data circulation and collaboration under privacy protection
node_exporter内存使用率不显示
Sophon autocv: help AI industrial production and realize visual intelligent perception
随机推荐
最大人工岛[如何让一个连通分量的所有节点都记录总节点数?+给连通分量编号]
Isprs2022 / Cloud Detection: Cloud Detection with Boundary nets Boundary Networks Based Cloud Detection
buuctf-pwn write-ups (9)
含重复元素取不重复子集[如何取子集?如何去重?]
Login and connect CDB and PDB
How can cluster deployment solve the needs of massive video access and large concurrency?
Sibling components carry out value transfer (there is a sequence displayed)
OpenShift常用管理命令杂记
Numerical calculation method chapter8 Numerical solutions of ordinary differential equations
[BeanShell] there are many ways to write data locally
【PaddlePaddle】 PaddleDetection 人脸识别 自定义数据集
热通孔的有效放置如何改善PCB设计中的热管理?
Penetrate the whole intranet through socks agent
南京大学:新时代数字化人才培养方案探讨
Sophon AutoCV:助力AI工业化生产,实现视觉智能感知
图片数据不够?我做了一个免费的图像增强软件
Leetcode notes: Weekly contest 300
rust统计文件中单词出现的次数
IDC report: Tencent cloud database ranks top 2 in the relational database market!
jdbc读大量数据导致内存溢出