当前位置:网站首页>2327. 知道秘密的人数(递推)
2327. 知道秘密的人数(递推)
2022-07-06 04:11:00 【Harris-H】
2327. 知道秘密的人数(递推)
一维dp就可以qwq。令 f i f_i fi表示第 i i i天新知道秘密的人数。
第 i i i天可以由 ( i − f o r g e t , i − d e l a y ] (i-forget,i-delay] (i−forget,i−delay] 递推。
显然可以预处理前缀和,做到 O ( n ) O(n) O(n)
最后的答案就是: ∑ i = n − f o r g e t + 1 n f i \sum\limits_{i=n-forget+1}^n f_i i=n−forget+1∑nfi
class Solution {
const int MOD = 1000000007;
public:
int peopleAwareOfSecret(int n, int delay, int forget) {
vector<long long> f(n + 1), g(n + 1);
f[1] = g[1] = 1;
for (int i = 2; i <= n; i++) {
int L = max(0, i - forget);
int R = max(0, i - delay);
f[i] = (g[R] - g[L] + MOD) % MOD;
g[i] = (g[i - 1] + f[i]) % MOD;
}
return (g[n] - g[max(0, n - forget)] + MOD) % MOD;
}
};
边栏推荐
- Unity中几个重要类
- Global and Chinese markets for patent hole oval devices 2022-2028: Research Report on technology, participants, trends, market size and share
- 2/10 parallel search set +bfs+dfs+ shortest path +spfa queue optimization
- DM8 backup set deletion
- Understanding of processes, threads, coroutines, synchronization, asynchrony, blocking, non blocking, concurrency, parallelism, and serialization
- [introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)
- The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched
- Practical development of member management applet 06 introduction to life cycle function and user-defined method
- Security xxE vulnerability recurrence (XXe Lab)
- 1291_ Add timestamp function in xshell log
猜你喜欢

About some basic DP -- those things about coins (the basic introduction of DP)

查询mysql数据库中各表记录数大小

关于进程、线程、协程、同步、异步、阻塞、非阻塞、并发、并行、串行的理解

Slow SQL fetching and analysis of MySQL database

How to modify field constraints (type, default, null, etc.) in a table

Path of class file generated by idea compiling JSP page

R note prophet

MLAPI系列 - 04 - 网络变量和网络序列化【网络同步】

【leetcode】1189. Maximum number of "balloons"

C mouse event and keyboard event of C (XXVIII)
随机推荐
Redis (replicate dictionary server) cache
查询mysql数据库中各表记录数大小
2/12 didn't learn anything
[FPGA tutorial case 12] design and implementation of complex multiplier based on vivado core
QML和QWidget混合开发(初探)
Global and Chinese markets for MRI safe implants 2022-2028: technology, participants, trends, market size and share Research Report
【FPGA教程案例12】基于vivado核的复数乘法器设计与实现
Viewing and verifying backup sets using dmrman
Conditionally [jsonignore]
ESP32_ FreeRTOS_ Arduino_ 1_ Create task
asp. Core is compatible with both JWT authentication and cookies authentication
How many of the 10 most common examples of istio traffic management do you know?
Proof of Stirling formula
Error 1045 (28000): access denied for user 'root' @ 'localhost' (using password: no/yes
Brief tutorial for soft exam system architecture designer | general catalog
2/10 parallel search set +bfs+dfs+ shortest path +spfa queue optimization
/usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
Yyds dry goods inventory hcie security Day11: preliminary study of firewall dual machine hot standby and vgmp concepts
MySQL learning record 13 database connection pool, pooling technology, DBCP, c3p0
Global and Chinese markets for medical gas manifolds 2022-2028: Research Report on technology, participants, trends, market size and share