当前位置:网站首页>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;
}
};
边栏推荐
- Memory management chapter of Kobayashi coding
- Wu Enda team 2022 machine learning course, coming
- Sophon autocv: help AI industrial production and realize visual intelligent perception
- About statistical power
- Xiaobai getting started with NAS - quick building private cloud tutorial series (I) [easy to understand]
- jdbc读大量数据导致内存溢出
- node_exporter内存使用率不显示
- 访问数据库使用redis作为mysql的缓存(redis和mysql结合)
- 吳恩達團隊2022機器學習課程,來啦
- To solve the stubborn problem of Lake + warehouse hybrid architecture, xinghuan Technology launched an independent and controllable cloud native Lake warehouse integrated platform
猜你喜欢
Huaxia Fund: sharing of practical achievements of digital transformation in the fund industry
寻找第k小元素 前k小元素 select_k
ViewPager + RecyclerView的内存泄漏
ConvMAE(2022-05)
图片数据不够?我做了一个免费的图像增强软件
About Estimation with Cross-Validation
About statistical power
分享:中兴 远航 30 pro root 解锁BL magisk ZTE 7532N 8040N 9041N 刷机 刷面具原厂刷机包 root方法下载
如何获取飞机穿过雷达两端的坐标
ISPRS2022/云检测:Cloud detection with boundary nets基于边界网的云检测
随机推荐
Simulate the hundred prisoner problem
吴恩达团队2022机器学习课程,来啦
瀚升优品app翰林优商系统开发功能介绍
@Extension、@SPI注解原理
集群部署如何解决海量视频接入与大并发需求?
[paddlepaddle] paddedetection face recognition custom data set
LeetCode笔记:Weekly Contest 300
EasyCVR接入设备开启音频后,视频无法正常播放是什么原因?
JVM third talk -- JVM performance tuning practice and high-frequency interview question record
星环科技数据安全管理平台 Defensor重磅发布
星环科技重磅推出数据要素流通平台Transwarp Navier,助力企业实现隐私保护下的数据安全流通与协作
How can cluster deployment solve the needs of massive video access and large concurrency?
Notes on common management commands of openshift
FCN: Fully Convolutional Networks for Semantic Segmentation
Vulnhub's darkhole_ two
使用QT遍历Json文档及搜索子对象
Easynmon Usage Summary
Fix vulnerability - mysql, ES
从类生成XML架构
Check namespaces and classes