当前位置:网站首页>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;
}
};
边栏推荐
- 10個 Istio 流量管理 最常用的例子,你知道幾個?
- Cross domain and jsonp details
- 2/12 didn't learn anything
- 颠覆你的认知?get和post请求的本质
- The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched
- lora网关以太网传输
- Global and Chinese markets for endoscopic drying storage cabinets 2022-2028: Research Report on technology, participants, trends, market size and share
- 记一次excel XXE漏洞
- WPF effect Article 191 box selection listbox
- Redis (replicate dictionary server) cache
猜你喜欢
Scalpel like analysis of JVM -- this article takes you to peek into the secrets of JVM
About some basic DP -- those things about coins (the basic introduction of DP)
[adjustable delay network] development of FPGA based adjustable delay network system Verilog
Record the pit of NETCORE's memory surge
《2022年中国银行业RPA供应商实力矩阵分析》研究报告正式启动
Figure application details
Ks003 mall system based on JSP and Servlet
【PSO】基于PSO粒子群优化的物料点货物运输成本最低值计算matlab仿真,包括运输费用、代理人转换费用、运输方式转化费用和时间惩罚费用
【FPGA教程案例11】基于vivado核的除法器设计与实现
How many of the 10 most common examples of istio traffic management do you know?
随机推荐
【可调延时网络】基于FPGA的可调延时网络系统verilog开发
C form application of C (27)
QML和QWidget混合开发(初探)
MySQL master-slave replication
Basic use of MySQL (it is recommended to read and recite the content)
Global and Chinese market of plasma separator 2022-2028: Research Report on technology, participants, trends, market size and share
Lambda expression learning
Custom event of C (31)
pd. to_ numeric
How to modify field constraints (type, default, null, etc.) in a table
Query the number and size of records in each table in MySQL database
Global and Chinese markets for endoscopic drying storage cabinets 2022-2028: Research Report on technology, participants, trends, market size and share
80% of the diseases are caused by bad living habits. There are eight common bad habits, which are both physical and mental
51nod 1130 n factorial length V2 (Stirling approximation)
Explain in simple terms node template parsing error escape is not a function
Redis (replicate dictionary server) cache
Overturn your cognition? The nature of get and post requests
Stable Huawei micro certification, stable Huawei cloud database service practice
AcWing 243. A simple integer problem 2 (tree array interval modification interval query)
DM8 archive log file manual switching