当前位置:网站首页>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;
}
};
边栏推荐
- VPP性能测试
- 软考 系统架构设计师 简明教程 | 总目录
- Solution to the problem that the root account of MySQL database cannot be logged in remotely
- TCP/IP协议里面的网关地址和ip地址有什么区别?
- 【leetcode】1189. Maximum number of "balloons"
- AcWing 243. A simple integer problem 2 (tree array interval modification interval query)
- math_极限&微分&导数&微商/对数函数的导函数推导(导数定义极限法)/指数函数求导公式推导(反函数求导法则/对数求导法)
- [Key shake elimination] development of key shake elimination module based on FPGA
- Database, relational database and NoSQL non relational database
- Hashcode and equals
猜你喜欢

Ipv4中的A 、B、C类网络及子网掩码

Overturn your cognition? The nature of get and post requests

Execution order of scripts bound to game objects

TCP/IP协议里面的网关地址和ip地址有什么区别?

综合能力测评系统

Stable Huawei micro certification, stable Huawei cloud database service practice

How many of the 10 most common examples of istio traffic management do you know?

【可调延时网络】基于FPGA的可调延时网络系统verilog开发

MySQL master-slave replication
![[tomato assistant installation]](/img/06/672a616d4fc2a43b83054eb1057628.jpg)
[tomato assistant installation]
随机推荐
Execution order of scripts bound to game objects
When debugging after pycharm remote server is connected, trying to add breakpoint to file that does not exist: /data appears_ sda/d:/segmentation
[disassembly] a visual air fryer. By the way, analyze the internal circuit
How to execute an SQL statement in MySQL
10個 Istio 流量管理 最常用的例子,你知道幾個?
自动化测试的好处
MySQL learning record 13 database connection pool, pooling technology, DBCP, c3p0
Mysql数据库慢sql抓取与分析
PTA tiantisai l1-078 teacher Ji's return (15 points) detailed explanation
Comprehensive ability evaluation system
Solve the compilation problem of "c2001: line breaks in constants"
2327. 知道秘密的人数(递推)
Benefits of automated testing
Use js to complete an LRU cache
Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage
Interface idempotency
[introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)
80% of the diseases are caused by bad living habits. There are eight common bad habits, which are both physical and mental
Class A, B, C networks and subnet masks in IPv4
使用JS完成一个LRU缓存