当前位置:网站首页>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;
}
};
边栏推荐
- [introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)
- Crawler notes: improve data collection efficiency! Use of proxy pool and thread pool
- Deep learning framework installation (tensorflow & pytorch & paddlepaddle)
- 10个 Istio 流量管理 最常用的例子,你知道几个?
- VPP性能测试
- MySql数据库root账户无法远程登陆解决办法
- Stack and queue
- Several important classes in unity
- Security xxE vulnerability recurrence (XXe Lab)
- 80% of the diseases are caused by bad living habits. There are eight common bad habits, which are both physical and mental
猜你喜欢

AcWing 243. A simple integer problem 2 (tree array interval modification interval query)

Stable Huawei micro certification, stable Huawei cloud database service 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](/img/41/27ce3741ef29e87c0f3b954fdef87a.png)
[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

【PSO】基于PSO粒子群优化的物料点货物运输成本最低值计算matlab仿真,包括运输费用、代理人转换费用、运输方式转化费用和时间惩罚费用

Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage

What is the difference between gateway address and IP address in tcp/ip protocol?
![[FPGA tutorial case 11] design and implementation of divider based on vivado core](/img/39/f337510c2647d365603a8485583a20.png)
[FPGA tutorial case 11] design and implementation of divider based on vivado core
![[adjustable delay network] development of FPGA based adjustable delay network system Verilog](/img/82/7ff7f99f5164f91fab7713978cf720.png)
[adjustable delay network] development of FPGA based adjustable delay network system Verilog

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

MySql数据库root账户无法远程登陆解决办法
随机推荐
Ipv4中的A 、B、C类网络及子网掩码
[introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)
VPP性能测试
/usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
Unity中几个重要类
Global and Chinese markets for medical gas manifolds 2022-2028: Research Report on technology, participants, trends, market size and share
Stable Huawei micro certification, stable Huawei cloud database service practice
2/11 matrix fast power +dp+ bisection
MySQL master-slave replication
Global and Chinese market of plasma separator 2022-2028: Research Report on technology, participants, trends, market size and share
/usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
729. 我的日程安排表 I(set or 动态开点线段树)
【按鍵消抖】基於FPGA的按鍵消抖模塊開發
Several important classes in unity
Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage
Mlapi series - 04 - network variables and network serialization [network synchronization]
Understanding of processes, threads, coroutines, synchronization, asynchrony, blocking, non blocking, concurrency, parallelism, and serialization
10 exemples les plus courants de gestion du trafic istio, que savez - vous?
【FPGA教程案例11】基于vivado核的除法器设计与实现
Stack and queue