当前位置:网站首页>2327. Number of people who know secrets (recursive)
2327. Number of people who know secrets (recursive)
2022-07-06 04:15:00 【Harris-H】
2327. Number of people who know the secret ( Recurrence )
A one-dimensional dp Can qwq. Make f i f_i fi It means the first one i i i Tianxin knows the number of Secrets .
The first i i i Days can be controlled by ( i − f o r g e t , i − d e l a y ] (i-forget,i-delay] (i−forget,i−delay] Recurrence .
Obviously, prefixes and , Achieve O ( n ) O(n) O(n)
The final answer is : ∑ 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;
}
};
边栏推荐
- Global and Chinese markets for otolaryngology devices 2022-2028: Research Report on technology, participants, trends, market size and share
- During pycharm debugging, the view is read only and pause the process to use the command line appear on the console input
- 绑定在游戏对象上的脚本的执行顺序
- 食品行业仓储条码管理系统解决方案
- 2/11 matrix fast power +dp+ bisection
- math_ Derivative function derivation of limit & differential & derivative & derivative / logarithmic function (derivative definition limit method) / derivative formula derivation of exponential functi
- Benefits of automated testing
- Record an excel xxE vulnerability
- How many of the 10 most common examples of istio traffic management do you know?
- 题解:《单词覆盖还原》、《最长连号》、《小玉买文具》、《小玉家的电费》
猜你喜欢
Security xxE vulnerability recurrence (XXe Lab)
Slow SQL fetching and analysis of MySQL database
Esp32 (based on Arduino) connects the mqtt server of emqx to upload information and command control
Maxay paper latex template description
[Zhao Yuqiang] deploy kubernetes cluster with binary package
Query the number and size of records in each table in MySQL database
自动化测试的好处
How many of the 10 most common examples of istio traffic management do you know?
Benefits of automated testing
Basic knowledge of binary tree, BFC, DFS
随机推荐
Network security - Security Service Engineer - detailed summary of skill manual (it is recommended to learn and collect)
Redis (replicate dictionary server) cache
10個 Istio 流量管理 最常用的例子,你知道幾個?
VNCTF2022 WriteUp
MySql數據庫root賬戶無法遠程登陸解决辦法
1008 circular right shift of array elements (20 points)
Several important classes in unity
VPP performance test
Record an excel xxE vulnerability
1291_Xshell日志中增加时间戳的功能
SSTI template injection explanation and real problem practice
[PSO] Based on PSO particle swarm optimization, matlab simulation of the calculation of the lowest transportation cost of goods at material points, including transportation costs, agent conversion cos
[FPGA tutorial case 12] design and implementation of complex multiplier based on vivado core
Record the pit of NETCORE's memory surge
Web components series (VII) -- life cycle of custom components
Solutions: word coverage restoration, longest serial number, Xiaoyu buys stationery, Xiaoyu's electricity bill
E. Best Pair
[FPGA tutorial case 11] design and implementation of divider based on vivado core
Data processing methods - smote series and adasyn
[introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)