当前位置:网站首页>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;
}
};
边栏推荐
- In Net 6 CS more concise method
- Maxay paper latex template description
- Mysql数据库慢sql抓取与分析
- P3033 [usaco11nov]cow steelchase g (similar to minimum path coverage)
- C form application of C (27)
- Yyds dry goods inventory web components series (VII) -- life cycle of custom components
- DM8 backup set deletion
- Ks003 mall system based on JSP and Servlet
- 食品行业仓储条码管理系统解决方案
- E. Best Pair
猜你喜欢
Plus d'un milliard d'utilisateurs de grandes entreprises comme Facebook ont été compromis, il est temps de se concentrer sur le did
Comprehensive ability evaluation system
Lora gateway Ethernet transmission
图应用详解
Ipv4中的A 、B、C类网络及子网掩码
Record the pit of NETCORE's memory surge
Esp32 (based on Arduino) connects the mqtt server of emqx to upload information and command control
Ks003 mall system based on JSP and Servlet
Tips for using dm8huge table
Record an excel xxE vulnerability
随机推荐
Global and Chinese markets for otolaryngology devices 2022-2028: Research Report on technology, participants, trends, market size and share
Conditionally [jsonignore]
Execution order of scripts bound to game objects
Redis (replicate dictionary server) cache
Several important classes in unity
Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage
Basic use of MySQL (it is recommended to read and recite the content)
Lambda expression learning
[FPGA tutorial case 12] design and implementation of complex multiplier based on vivado core
About some basic DP -- those things about coins (the basic introduction of DP)
Lombok原理和同时使⽤@Data和@Builder 的坑
Scalpel like analysis of JVM -- this article takes you to peek into the secrets of JVM
Global and Chinese markets for fire resistant conveyor belts 2022-2028: Research Report on technology, participants, trends, market size and share
Database, relational database and NoSQL non relational database
【可调延时网络】基于FPGA的可调延时网络系统verilog开发
图应用详解
What is the difference between gateway address and IP address in tcp/ip protocol?
脚本生命周期
Network security - Security Service Engineer - detailed summary of skill manual (it is recommended to learn and collect)
Practical development of member management applet 06 introduction to life cycle function and user-defined method