当前位置:网站首页>LeetCode 6109. 知道秘密的人数
LeetCode 6109. 知道秘密的人数
2022-07-05 18:12:00 【HumbleFool】
LeetCode 6109. 知道秘密的人数
线性DP + 前缀和优化
/* f[i][j]表示前i天,记得秘密j天的数量 j == 1: 一共有 delay <= j < forget数量 f[i][j] = f[i - 1][delay] + f[i - 1][delay + 1] ... f[i - 1][forget - 1]; 这里求了连续和,暴力n^3,会超时,前缀和优化 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;
}
};
边栏推荐
- Record a case of using WinDbg to analyze memory "leakage"
- 第十一届中国云计算标准和应用大会 | 云计算国家标准及白皮书系列发布 华云数据全面参与编制
- How to obtain the coordinates of the aircraft passing through both ends of the radar
- Star Ring Technology launched transwarp Navier, a data element circulation platform, to help enterprises achieve secure data circulation and collaboration under privacy protection
- About statistical power
- Sophon CE Community Edition is online, and free get is a lightweight, easy-to-use, efficient and intelligent data analysis tool
- IDC report: Tencent cloud database ranks top 2 in the relational database market!
- Introduction to the development function of Hanlin Youshang system of Hansheng Youpin app
- Xiaobai getting started with NAS - quick building private cloud tutorial series (I) [easy to understand]
- Introduction to VC programming on "suggestions collection"
猜你喜欢

第十一届中国云计算标准和应用大会 | 华云数据成为全国信标委云计算标准工作组云迁移专题组副组长单位副组长单位

Tupu software digital twin | visual management system based on BIM Technology

nacos -分布式事务-Seata** linux安装jdk ,mysql5.7启动nacos配置ideal 调用接口配合 (保姆级细节教程)

如何获取飞机穿过雷达两端的坐标

JVM第三话 -- JVM性能调优实战和高频面试题记录

第十届全球云计算大会 | 华云数据荣获“2013-2022十周年特别贡献奖”

《2022中国信创生态市场研究及选型评估报告》发布 华云数据入选信创IT基础设施主流厂商!

Fix vulnerability - mysql, ES

南京大学:新时代数字化人才培养方案探讨

Binder开辟线程数过多导致主线程ANR异常
随机推荐
Binder开辟线程数过多导致主线程ANR异常
Check namespaces and classes
Eliminate the writing of 'if () else{}'
第十一届中国云计算标准和应用大会 | 云计算国家标准及白皮书系列发布 华云数据全面参与编制
【在优麒麟上使用Electron开发桌面应】
nano的CAN通信
ISPRS2020/云检测:Transferring deep learning models for cloud detection between Landsat-8 and Proba-V
Introduction to Resampling
buuctf-pwn write-ups (9)
Sophon CE Community Edition is online, and free get is a lightweight, easy-to-use, efficient and intelligent data analysis tool
RSE2020/云检测:基于弱监督深度学习的高分辨率遥感图像精确云检测
开户注册挖财安全吗?有没有风险的?靠谱吗?
New words new words new words new words [2]
Crontab 日志:如何记录我的 Cron 脚本的输出
生词生词生词生词[2]
记一次使用Windbg分析内存“泄漏”的案例
Logical words in Articles
小林coding的内存管理章节
Introduction to the development function of Hanlin Youshang system of Hansheng Youpin app
Fix vulnerability - mysql, ES