当前位置:网站首页>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;
}
};
边栏推荐
- 解决“C2001:常量中有换行符“编译问题
- One question per day (Mathematics)
- Global and Chinese market of rubber wheel wedges 2022-2028: Research Report on technology, participants, trends, market size and share
- Basic use of MySQL (it is recommended to read and recite the content)
- Data processing methods - smote series and adasyn
- 电脑钉钉怎么调整声音
- 颠覆你的认知?get和post请求的本质
- Python book learning notes - Chapter 09 section 01 create and use classes
- Record the pit of NETCORE's memory surge
- hashlimit速率控制
猜你喜欢
Record an excel xxE vulnerability
Web components series (VII) -- life cycle of custom components
Tips for using dm8huge table
10 exemples les plus courants de gestion du trafic istio, que savez - vous?
Lombok principle and the pit of ⽤ @data and @builder at the same time
Network security - Security Service Engineer - detailed summary of skill manual (it is recommended to learn and collect)
【PSO】基于PSO粒子群优化的物料点货物运输成本最低值计算matlab仿真,包括运输费用、代理人转换费用、运输方式转化费用和时间惩罚费用
Lombok原理和同时使⽤@Data和@Builder 的坑
MySQL master-slave replication
Ipv4中的A 、B、C类网络及子网掩码
随机推荐
. Net interprocess communication
查询mysql数据库中各表记录数大小
1291_Xshell日志中增加时间戳的功能
What is the difference between gateway address and IP address in tcp/ip protocol?
Security xxE vulnerability recurrence (XXe Lab)
HotSpot VM
Lombok principle and the pit of ⽤ @data and @builder at the same time
PTA tiantisai l1-078 teacher Ji's return (15 points) detailed explanation
自动化测试的好处
Chinese brand hybrid technology: there is no best technical route, only better products
1008 circular right shift of array elements (20 points)
Overturn your cognition? The nature of get and post requests
TCP/IP协议里面的网关地址和ip地址有什么区别?
[introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)
Benefits of automated testing
Fundamentals of SQL database operation
Développement d'un module d'élimination des bavardages à clé basé sur la FPGA
脚本生命周期
Global and Chinese markets for fire resistant conveyor belts 2022-2028: Research Report on technology, participants, trends, market size and share
2327. 知道秘密的人数(递推)