当前位置:网站首页>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;
}
};
边栏推荐
- 10 exemples les plus courants de gestion du trafic istio, que savez - vous?
- Codeforces Round #770 (Div. 2) B. Fortune Telling
- P2022 有趣的数(二分&数位dp)
- E. Best Pair
- Global and Chinese markets for medical gas manifolds 2022-2028: Research Report on technology, participants, trends, market size and share
- Fedora/REHL 安装 semanage
- Class A, B, C networks and subnet masks in IPv4
- 80% of the diseases are caused by bad living habits. There are eight common bad habits, which are both physical and mental
- [Zhao Yuqiang] deploy kubernetes cluster with binary package
- /usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
猜你喜欢

Slow SQL fetching and analysis of MySQL database

In depth MySQL transactions, stored procedures and triggers
![[tomato assistant installation]](/img/06/672a616d4fc2a43b83054eb1057628.jpg)
[tomato assistant installation]

What is the difference between gateway address and IP address in tcp/ip protocol?

How does technology have the ability to solve problems perfectly

解决“C2001:常量中有换行符“编译问题

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

【FPGA教程案例11】基于vivado核的除法器设计与实现

User datagram protocol UDP

Data processing methods - smote series and adasyn
随机推荐
POI add border
MySQL learning record 13 database connection pool, pooling technology, DBCP, c3p0
Stable Huawei micro certification, stable Huawei cloud database service practice
Cross domain and jsonp details
自动化测试的好处
Global and Chinese markets for medical gas manifolds 2022-2028: Research Report on technology, participants, trends, market size and share
R note prophet
Understanding of processes, threads, coroutines, synchronization, asynchrony, blocking, non blocking, concurrency, parallelism, and serialization
2/12 didn't learn anything
Class A, B, C networks and subnet masks in IPv4
MySQL master-slave replication
Global and Chinese market of aircraft anti icing and rain protection systems 2022-2028: Research Report on technology, participants, trends, market size and share
C. The Third Problem(找规律)
【可调延时网络】基于FPGA的可调延时网络系统verilog开发
729. 我的日程安排表 I(set or 动态开点线段树)
pd. to_ numeric
PTA tiantisai l1-078 teacher Ji's return (15 points) detailed explanation
P2022 有趣的数(二分&数位dp)
IDEA编译JSP页面生成的class文件路径
【PSO】基于PSO粒子群优化的物料点货物运输成本最低值计算matlab仿真,包括运输费用、代理人转换费用、运输方式转化费用和时间惩罚费用